Results 1 to 7 of 7

Thread: QStringList in QObject::connect

  1. #1
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default QStringList in QObject::connect

    Hello,

    I'm trying to pass a QStringList using the signal slot, but when I try to use the QStringList in the slot it contains garbage (and exceptions). I set up the "connect" call to use QStringList* because otherwise the connect call fails.
    Qt Code:
    1. QObject::connect (m_emitter_class,
    2. SIGNAL(removeGamesSignal (int, QStringList* )),
    3. m_pkr_receiver_class,
    4. SLOT(invokeGamesRemoval (int, QStringList* )),
    5. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

    I then tried the following as well:
    Qt Code:
    1. QObject::connect (m_emitter_class,
    2. SIGNAL(removeGamesSignal (int, QStringList& )),
    3. m_pkr_receiver_class,
    4. SLOT(invokeGamesRemoval (int, QStringList& )),
    5. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 
    This does not work, the error says:
    QObject::connect: Cannot queue arguments of type 'QStringList&'

    When I use Qt:: DirectConnection with the 'QStringList&' signature the QObject::connect suceeds.

    It is possible to send a QStringList using a signal and Qt::QueuedConnection?

    Thanks,
    DP

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList in QObject::connect

    With queued connections, the parameters must be of types that are known to Qt's meta-object system (basically those understood by QVariant), because Qt needs to copy the arguments to store them in an event behind the scenes.

    call qRegisterMetaType() to register the data type before you establish the connection.

  3. The following user says thank you to munna for this useful post:

    DPinLV (6th September 2006)

  4. #3
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList in QObject::connect

    Quote Originally Posted by munna
    With queued connections, the parameters must be of types that are known to Qt's meta-object system (basically those understood by QVariant), because Qt needs to copy the arguments to store them in an event behind the scenes.

    call qRegisterMetaType() to register the data type before you establish the connection.
    Thanks Munna,

    There is no problem with doing this to Qt types (i.e. QStringList), this will not cause a conflict?
    Qt Code:
    1. qRegisterMetaType<QStringList>("QStringList");
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList in QObject::connect

    Quote Originally Posted by DPinLV
    There is no problem with doing this to Qt types (i.e. QStringList), this will not cause a conflict?
    I don't think so. Give it a try.

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

    Default Re: QStringList in QObject::connect

    ...and the same issue has already been solved in thread: QStringList with Signal/Slot.
    J-P Nurmi

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QStringList in QObject::connect

    Essentially you can't pass non-const references to a queued connection (as it doesn't make any sense). You'd have to use const QStringList& instead (but you wouldn't be able to change its contents). Using pointers is tricky too, because only a pointer is copied when the signal is emitted. If "in the meantime" (before the slot is executed) you delete the object, you'll end up with an invalid pointer and a possible segfault.

  8. #7
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList in QObject::connect

    Quote Originally Posted by jpn
    ...and the same issue has already been solved in thread: QStringList with Signal/Slot.
    Thanks, I noticed there was an existing thread when I received my subscriber email from QT regarding this thread. After looking at the existing thread on this subject I was able to get it working. I use the following which succeeds:
    Qt Code:
    1. qRegisterMetaType<QStringList>("QStringList");
    2. QObject::connect (m_emitter_class,
    3. SIGNAL(removeGamesSignal (int, const QStringList& )),
    4. m_pkr_receiver_class,
    5. SLOT(invokeGamesRemoval (int, const QStringList& )),
    6. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 
    I did not try the QVariant option mentioned in the previous thread since it seems like a matter of personal preference. If anyone disagrees please let me know why.

    Quote Originally Posted by wysota
    Essentially you can't pass non-const references to a queued connection (as it doesn't make any sense). You'd have to use const QStringList& instead (but you wouldn't be able to change its contents). Using pointers is tricky too, because only a pointer is copied when the signal is emitted. If "in the meantime" (before the slot is executed) you delete the object, you'll end up with an invalid pointer and a possible segfault.
    Thanks for the explanation of what is going on under the covers with signals I appreciate that. I'm trying to learn what the Signals/Slots are doing as far as when they copy data, etc.
    Thanks, wysota, jpn, and munna.

Similar Threads

  1. QStringList straight to file
    By freak in forum Newbie
    Replies: 2
    Last Post: 13th June 2006, 22:38
  2. QStringList with Signal/Slot
    By Sivert in forum Qt Programming
    Replies: 4
    Last Post: 3rd May 2006, 20:34
  3. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48
  4. qt4 QStringList with model/view
    By incapacitant in forum Newbie
    Replies: 23
    Last Post: 16th March 2006, 19:39
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 21:24

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.