0

I'm trying to catch a signal of a ListView in my .qml file, so I'm doing:

ListView *userList = root->findChild<ListView*>("userList");
Q_ASSERT(userList);

It gets the list, and the when I try:

Q_ASSERT(connect(userList, SIGNAL(triggered(QVariantList indexPath)), this, SLOT(onUserListTriggered(QVariantList indexPath))));

I get this error:

Object::connect: No such signal bb::cascades::QmlListView::triggered(QVariantList indexPath)
Object::connect:  (sender name:   'userList')
ASSERT: "connect(userList, SIGNAL(triggered(QVariantList indexPath)), this, SLOT(onUserListTriggered(QVariantList indexPath)))"

It makes no sense. The documentation of ListView tells the class emits this signal, and I can see it in the header listview.h as

Q_SIGNALS:
/*!
        * @brief Emitted when a list item is triggered by the user.
        *
        * Typically, this signal is emitted when an item is tapped by the user 
        * with the intention to execute some action associated with it. 
        * This signal is, for example, not emitted when items are tapped 
        * during multiple selection, where the intention is to select the 
        * tapped item and not trigger an action associated with it.
        *
        * @param indexPath Index path to the triggered item.
        */
        void triggered(QVariantList indexPath);
Dielson Sales
  • 1,715
  • 1
  • 20
  • 25

2 Answers2

2

Specify only parameter's data type while connecting a signal to slot. Replace connect call statement with below mentioned statement.

bool ok = connect(userList, SIGNAL(triggered(QVariantList)), 
  this, SLOT(onUserListTriggered(QVariantList)));
// Q_ASSERT the bool so that the connect will be included in Release code
Q_ASSERT(ok);
craigmj
  • 4,827
  • 2
  • 18
  • 22
Nishant Shah
  • 1,590
  • 1
  • 15
  • 25
  • 3
    This is _VERY WRONG_. The `connect` code is fine, but wrapping it in `Q_ASSERT` means that it will be excluded in a Release build. In other words, it will work fine in your debug builds, and as soon as you release your code, the `connect` will never be called. See http://stackoverflow.com/questions/12573230/q-assert-release-build-semantics for the details. I've edited above to correct. – craigmj Feb 10 '13 at 13:29
0

I've also found it necessary to put the full namespace. This won't be necessary for your example, but for example I've had to do:

if (!connect(root, SIGNAL(popTransitionEnded(bb::cascades::Page*)), this,
    SLOT(navPagePopped(bb::cascades::Page*)))) {
    qDebug() << "UNABLE to connect popTransitionEnded to navPagePopped";
}

I'm guessing that the Qt framework uses the full namespace of parameters when it creates its signal tables.

craigmj
  • 4,827
  • 2
  • 18
  • 22