Results 1 to 9 of 9

Thread: unable to establish queued connection with QList of own class pointers

  1. #1
    Join Date
    Jul 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default unable to establish queued connection with QList of own class pointers

    Hi,

    I am not able to establish a queued connection of the form

    Qt Code:
    1. connect(parent(),SIGNAL(signal(QList<const RealDataHandler *>,RealDataHandler *,double)),&calculationClass,SLOT(slot(QList<const RealDataHandler*>,RealDataHandler*,double)));
    To copy to clipboard, switch view to plain text mode 

    I always get the following error:

    Qt Code:
    1. QObject::connect: Cannot queue arguments of type 'QList<const RealDataHandler*>'
    2. (Make sure 'QList<const RealDataHandler*>' is registered using qRegisterMetaType().)
    To copy to clipboard, switch view to plain text mode 

    I already registered both, RealDataHandler and QList<const RealDataHandler*> as the very first command of my main.cpp, even tried it with RealDataHandler* allone.

    Qt Code:
    1. typedef QList<const RealDataHandler*> RealDataHandlerList;
    2. // ....
    3. qRegisterMetaType<RealDataHandler>("RealDataHandler");
    4. qRegisterMetaType<RealDataHandlerList >("RealDataHandlerList");
    To copy to clipboard, switch view to plain text mode 

    I really don't understand this. It should not be so difficult to send a list of pointers, should it? Can anyone explain to me what I am doing wrong? Many thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: unable to establish queued connection with QList of own class pointers

    What happens when you use your typedef in the signal?

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

    Default Re: unable to establish queued connection with QList of own class pointers

    Hmm... does having a list of const pointers even work? How do you add items there?

    Did you declare a metatype for your class list prior to using qRegisterMetaType?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: unable to establish queued connection with QList of own class pointers

    what should be the problem with lists of const pointers?

    declaring the metatype before registration does not help here.

    What happens when you use your typedef in the signal?
    This is the solution. Many thanks!

    Still I don't understand why I can't use the list directly without defining my own type.

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

    Default Re: unable to establish queued connection with QList of own class pointers

    Quote Originally Posted by Gh0str1d3r View Post
    what should be the problem with lists of const pointers?
    How do you assign a value to a const pointer?

    Still I don't understand why I can't use the list directly without defining my own type.
    Because moc doesn't like templates.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: unable to establish queued connection with QList of own class pointers

    Quote Originally Posted by wysota View Post
    How do you assign a value to a const pointer?
    I don't want to assign anything here, I just want to put the pointers in a list. QList::append(T) does not change T, so T can be const.

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

    Default Re: unable to establish queued connection with QList of own class pointers

    I'm not talking about this particular case here. I mean using such a list is... akward, for example you can't do this:

    Qt Code:
    1. foreach(const RealDataHandler *ptr, yourList){ // assignment, invalid
    2. doSomething(ptr);
    3. }
    To copy to clipboard, switch view to plain text mode 

    You have to do:
    Qt Code:
    1. for(int i=0;i<yourList.count();++i){
    2. const RealDataHandler *ptr = yourList.at(i); // initialization, not assignment, valid
    3. doSomething(ptr);
    4. }
    To copy to clipboard, switch view to plain text mode 

    etc.

    As for append() - it works because QList is an advanced class that doesn't preallocate objects in the list, it just preallocates space for them.

    By the way, as you are asking for queued connections, I'm assuming you are using threads -- remember you are passing unprotected objects between threads which essentially leads (or may lead) to trouble.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jul 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: unable to establish queued connection with QList of own class pointers

    ok, that's true, didn't think about the foreach loop.

    You are right, we are talking about inter-thread communication. What would be the way to protect the object? Transmitting a QMutex with it? Like this

    Qt Code:
    1. connect(parent(),SIGNAL(signal(QList<const RealDataHandler *>,RealDataHandler *,double,QMutex&)),&calculationClass,SLOT(slot(QList<const RealDataHandler*>,RealDataHandler*,double,QMutex&)));
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: unable to establish queued connection with QList of own class pointers

    Certainly not. The mutex should be part of the object and the list should probably be in a has-a relationship rather than is-a. Better yet, don't pass the list around (it may require the list to be copied!). Let one thread notify the other that something happened so that the other can access the list directly (or something like that).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Telnet connection does not establish...
    By gentlesea in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2011, 09:54
  2. Replies: 5
    Last Post: 20th April 2010, 17:48
  3. Queued connection fails on own class
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2008, 18:50
  4. QSQLITE | unable to establish connection
    By suresh in forum Newbie
    Replies: 4
    Last Post: 1st July 2008, 11:17
  5. queued signal/slot connection with QList<int>
    By smalls in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 14:32

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.