2013-01-22 23 views
0

我想趕上我.qml文件一個ListView的信號,所以我做:沒有這樣的信號BB ::級聯:: QmlListView ::觸發(QVariantList indexPath)

​​

它得到的名單,而當我嘗試:

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

這是沒有意義的。所述documentation of 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); 

回答

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); 
+0

沒錯,謝謝! –

+3

這是_VERY WRONG_。 'connect'代碼很好,但是將其封裝在'Q_ASSERT'中意味着它將在Release版本中被排除。換句話說,它可以在你的調試版本中正常工作,只要你釋放你的代碼,'connect'永遠不會被調用。有關詳細信息,請參閱http://stackoverflow.com/questions/12573230/q-assert-release-build-semantics。我已經在上面編輯過來糾 – craigmj

+0

恩,謝謝你的糾正。 –

0

我也發現有必要把完整的命名空間。這會不會是必要爲您的例子,但例如,我不得不這樣做:

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

我猜測,Qt框架使用的參數完整的命名空間時,它會創建信號表。

+0

我也有這個例子的問題,因爲它找不到沒有完整名稱空間的信號...... –