API does not follow QML style

Bug #1393261 reported by Michael Zanetti
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical System Image
Fix Released
Undecided
Unassigned
ubuntu-push-qml (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

The PushClient API does not have parameter names, which causes troubles using it in a QML like manner:

Usually in QML one would use the PushClient like this:

PushClient {
  onError: {
    print("PushClient error", error);
  }
}

However, due to the fact that the error() signal is declared as "void error(QString)" instead of "void error(QString error)" this is not possible and the above code results in printing the function pointer to the error function.

Also, for performance reasons, non-basic parameters should be changed to use const &, like

void error(const QString &error)

This affects all signals of the PushClient class.

Related branches

Changed in ubuntu-push:
importance: Undecided → High
assignee: nobody → John Lenton (chipaca)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

After this change, the example in here [1] can be updated to use the QML style of doing things, which also has the advantage that it allows removing the undefined reference to messageList from the example code.

[1] http://developer.ubuntu.com/apps/platform/guides/push-notifications-client-guide/

Revision history for this message
John Lenton (chipaca) wrote :

Well, the “undefined reference” would remain, because you want to handle notifications as they come in (right? or is there a more QMLish way of doing that too?), and the error handler would still be that.

I know *no* QML; can the error handler be specified as

    onError: messageList.handle_error

or does it have to be

    onError: {
        messageList.handle_error(error)
    }

?

We should probably change the example to make it explicit that messageList is some other part of the app you're building.

Revision history for this message
Michael Zanetti (mzanetti) wrote :

same there. You'd do:

PushClient {
  onNotificationsChanged: {
    print("got notifications:", notifications)
    // Do something useful with them
  }
}

Revision history for this message
Michael Zanetti (mzanetti) wrote :

Not saying that's the best to put into the example code, but you could even do something like:

PushClient {
  id: pushClient
}

ListView {
  model: pushClient.notifications
}

This would automatically update the listview whenever the notifications change.

For the example I'd go for:

PushClient {
  onError: {
    console.warn("PushClient error:", error)
  }
  onNotificationsChanged: {
    console.log("Notifications received:", notifications)
    // Do something useful with them
  }
}

(I did not test this, so there might be some typos or similar, but I'm sure you get the idea)

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-push-qml - 0.1+15.04.20141117-0ubuntu1

---------------
ubuntu-push-qml (0.1+15.04.20141117-0ubuntu1) vivid; urgency=low

  [ Michael Zanetti ]
  * constify, use references and add parameter names (LP: #1393261)
 -- Ubuntu daily release <email address hidden> Mon, 17 Nov 2014 16:46:19 +0000

Changed in ubuntu-push-qml (Ubuntu):
status: New → Fix Released
John Lenton (chipaca)
no longer affects: ubuntu-push
Changed in canonical-devices-system-image:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.