Results 1 to 6 of 6

Thread: Signal arguments limit to ?

  1. #1
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Question Signal arguments limit to ?

    The docs say to not use custom types in your signals/slots to make them more flexible. Cool with me, makes sense.

    But what about QtCore types? Would passing a QHash be a bad idea? It won't let me ("not defined in this scope"), so I am assuming that at least one troll thought it a bad idea. If it is then it is, I would just like to know why.

    Cheers
    --
    The Real Bill

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Signal arguments limit to ?

    Can we ask a piece of code?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: Signal arguments limit to ?

    Quote Originally Posted by zlatko
    Can we ask a piece of code?
    I dunno, what do you want to ask it?

    Anyway .. here it is (comments stripped for space savings):

    Qt Code:
    1. #include <QtCore>
    2. class ConnectionThread : public QThread {
    3. Q_OBJECT
    4. public:
    5. ConnectionThread(int socketDescriptor, QObject *parent);
    6. ~ConnectionThread();
    7. void run();
    8. void sendReply(QString reply);
    9. ...
    10. signals:
    11. void error(QTcpSocket::SocketError socketError);
    12. void sendPFdata(QHash pfdata);
    13. ...
    To copy to clipboard, switch view to plain text mode 

    Resulting error message:
    error: `QHash' was not declared in this scope

    Chaning it to a QString allows it to compile, but naturally won't "work" (since I need to pass the hash, not a string). I suppose if it comes down to it I will use a QString and turn it into a hash on the other end but I'd rather not.
    --
    The Real Bill

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Signal arguments limit to ?

    Maiby its stupid remark but have you try #include<QHash>
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal arguments limit to ?

    Quote Originally Posted by ucntcme
    I dunno, what do you want to ask it?
    Resulting error message:
    error: `QHash' was not declared in this scope
    QHash is a class template. Try this (substitute type1 and type2 with correct types):
    Qt Code:
    1. typedef QHash< type1, type2 > MyHash;
    2.  
    3. class ConnectionThread : public QThread {
    4. // ...
    5. signals:
    6. // ...
    7. void sendPFdata(MyHash pfdata);
    8. }
    To copy to clipboard, switch view to plain text mode 
    You might have some problems with that class, because part of it will live in one thread and part (the run() method) in another. You might have to set the connection type to queued connection explicitly.

  6. #6
    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: Signal arguments limit to ?

    If you want to use QHash as a signal parameter, you'll need to inform Qt meta type mechanism about it using Q_DECLARE_METATYPE().

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  3. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 14:11
  4. Replies: 2
    Last Post: 17th May 2006, 22:01

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.