Results 1 to 2 of 2

Thread: custom types for signal/slot arguments

  1. #1
    Join Date
    Nov 2011
    Location
    Belgium
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default custom types for signal/slot arguments

    Hi.

    In the Signals and Slots overview, I read that

    Signals and slots can take any number of arguments of any type. They are completely type safe.
    Actually trying that out, however, showed that a member function with a typedeffed argument is not recognized:



    Qt Code:
    1. class IndexToEnum : public QObject {
    2. Q_OBJECT
    3. ...
    4. typedef QAudio::Mode mode;
    5. signals:
    6. void modeChanged( QAudio::Mode mode );
    7. void modeChangedT( e mode );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. IndexToEnum* e = new IndexToEnum;
    2. // works just fine:
    3. connect( e, SIGNAL( modeChanged(QAudio::Mode) ), this, SLOT( modeChanged(QAudio::Mode) ) );
    4. // triggers "No such signal ModeEnum::modeChangedT(IndexToEnum::e)"
    5. connect( e, SIGNAL( modeChangedT(IndexToEnum::e) ), this, SLOT( modeChangedT(IndexToEnum::e) ) );
    To copy to clipboard, switch view to plain text mode 

    Note: I was actually tweaking the audiodevices demo, where I wanted to insert an index->enum convertor between the modeBox and the AudioTest object.

    Is this improper use of the signal/slot mechanism? Are there any other restrictions on the argument types?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: custom types for signal/slot arguments

    Qt Code:
    1. void modeChangedT( e mode );
    To copy to clipboard, switch view to plain text mode 
    What is "e" in above code ? If its a typedef, then read here about limitations:
    Enums and Typedefs Must Be Fully Qualified for Signal and Slot Parameters

    When checking the signatures of its arguments, QObject::connect() compares the data types literally. Thus, Alignment and Qt::Alignment are treated as two distinct types. To work around this limitation, make sure to fully qualify the data types when declaring signals and slots, and when establishing connections.
    So you should declare:
    Qt Code:
    1. void modeChangedT( IndexToEnum::e );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Connecting custom signal and slot
    By DmitryNik in forum Newbie
    Replies: 4
    Last Post: 12th September 2011, 14:15
  2. timeout() signal to a slot with arguments
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 3
    Last Post: 11th June 2010, 14:48
  3. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28
  4. What argument types for Signal/Slot?
    By DPinLV in forum Qt Programming
    Replies: 5
    Last Post: 2nd August 2006, 19:08
  5. custom slot/signal
    By awnjoor in forum Newbie
    Replies: 17
    Last Post: 17th July 2006, 08:05

Tags for this Thread

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.