Results 1 to 7 of 7

Thread: QObject::connect: Cannot queue arguments of type 'QModelIndex'

  1. #1
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QObject::connect: Cannot queue arguments of type 'QModelIndex'

    Hello all,
    i am porting a python application from qt3 to qt4 but i have some problem. Here is a minimal program showing the error i'm getting:

    Qt Code:
    1. import sys,thread
    2. from PyQt4 import QtGui, QtCore
    3.  
    4. app = QtGui.QApplication(sys.argv)
    5. win = QtGui.QMainWindow()
    6. table = QtGui.QTableWidget(1, 2)
    7. win.setCentralWidget(table)
    8. def change_row_count():
    9. table.setRowCount(2)
    10. thread.start_new_thread(change_row_count, ())
    11. win.show()
    12. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    and this is what i get (under linux):
    $ python test.py
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)
    QObject::connect: Cannot queue arguments of type 'QModelIndex'
    (Make sure 'QModelIndex' is registed using qRegisterMetaType().)

    changing rowCount in the main thread or commenting out setRowCount call in change_row_count() makes those errors disappear.

    What's wrong?

    Thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject::connect: Cannot queue arguments of type 'QModelIndex'

    Yes. Seems like QModelIndex is not known to QMetaType, which is weird, because there are Qt signals that pass QModelIndex parameters.

    Try using qRegisterMetatType<QModelIndex>("QModelIndex") somewhere before connecting.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QObject::connect: Cannot queue arguments of type 'QModelIndex'

    You should not touch GUI in a worker thread. The GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. QModelIndex is not registered because it should not be passed as a parameter in queued signals.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QObject::connect: Cannot queue arguments of type 'QModelIndex'

    Thanks all.

    what i need is to fill the table with the results of a long computation without freezing the gui while processing. What's the simplest way to achieve this?

    since you warned me that only the main thread should touch the gui, i would create a working thread to update a shared variable (locked by a mutex) and then emit a signal when finished. the gui (main) thread would then call a slot to display data in the table.
    i am a newbie at threads, so is this correct? is there something else i should take care of?

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject::connect: Cannot queue arguments of type 'QModelIndex'

    Yes that is correct. You can either hold a global data structure to store intermediary computations or you can do everything in the thread and at the end emit a signal with this data as parameter(s).

    Regards

  6. #6
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QObject::connect: Cannot queue arguments of type 'QModelIndex'

    Quote Originally Posted by marcel View Post
    Yes that is correct. You can either hold a global data structure to store intermediary computations or you can do everything in the thread and at the end emit a signal with this data as parameter(s).

    Regards
    Only one last question: if i use your solution (i.e. emitting a signal with my data as a parameter) and all interthread communication happens only using that emitted data, i don't need any mutex, right?
    I mean, if i press two times a button to process data, the signal would be emitted two times, but since the connected slot is in the main program (which alters the table) the two slots are executed sequentially. Correct?

    Thanks again

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject::connect: Cannot queue arguments of type 'QModelIndex'

    Only one last question: if i use your solution (i.e. emitting a signal with my data as a parameter) and all interthread communication happens only using that emitted data, i don't need any mutex, right?
    I mean, if i press two times a button to process data, the signal would be emitted two times, but since the connected slot is in the main program (which alters the table) the two slots are executed sequentially. Correct?
    Not really. Sending the event twice causes to events(QEvent) to be posted in the GUI's event queue. It will handle them asynchronously, so you are not guaranteed the event for the first button press gets handled first(but that's only if order matters to you).

    The problem is that your worker thread could corrupt the static data while the GUI is processing the first event(thus reading data).

    So I think the best solution is not to have only a data structure, but a stack of these data structures. The worker thread pushes new data in the stack while the GUI thread pops data from the stack.
    So the GUI thread should check the stack periodically, to see if something new has arrived. You could implement this very easy with a QTimer, with a 200-300 msec delay.

    So pressing the button just causes the worker thread to add data to the stack.

  8. The following user says thank you to marcel for this useful post:

    borges (21st September 2007)

Similar Threads

  1. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 18:04
  2. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 20th July 2007, 00:38
  3. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 21:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.