Results 1 to 7 of 7

Thread: QStringList in QObject::connect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.

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

    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
  •  
Qt is a trademark of The Qt Company.