0

我试图在我的 .qml 文件中捕获 ListView 的信号,所以我正在这样做:

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

它获取列表,以及当我尝试时:

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

我收到此错误:

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)))"

这没有道理。ListView的文档告诉类发出这个信号,我可以在标题 listview.h 中看到它

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);
4

2 回答 2

2

将信号连接到插槽时仅指定参数的数据类型。用下面提到的语句替换连接调用语句。

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);
于 2013-01-22T04:45:51.747 回答
0

我还发现有必要放置完整的命名空间。对于您的示例,这不是必需的,但例如我必须这样做:

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

我猜 Qt 框架在创建信号表时使用了完整的参数命名空间。

于 2013-01-22T08:06:23.100 回答