Results 1 to 9 of 9

Thread: signals and slot...can i select my option ?

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default signals and slot...can i select my option ?

    hi..
    i am writting this statement but it doesnt seem to work..
    Qt Code:
    1. void Control::connectButton()
    2. {
    3. connect(accept,SIGNAL(clicked()),SIGNAL(buttonConnected(0)));
    4. }
    5. ..
    6. connect(contrl,SIGNAL(buttonConnected(int)),training,SLOT(informRecord(int)));
    To copy to clipboard, switch view to plain text mode 
    .
    first my question are the above statement correct ?
    my main purpose of putting 0 in the buttonConnected parameter is that that i can use it as option/choice i.e for selection
    like i want to do also
    connect(reject,SIGNAL(clicked()),SIGNAL(buttonConn ected(1)));
    so if its accept buttonConnected() passes with 0 and if itz reject buttonConnected() passes with 1..

  2. #2
    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: signals and slot...can i select my option ?


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

    salmanmanekia (7th August 2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signals and slot...can i select my option ?

    now i am trying this way but it also seems not working

    Qt Code:
    1. void Control::connectButton()
    2. {
    3. if (connect(accept,SIGNAL(clicked()),this,SLOT(checkOption(int))))
    4. checkOption(0);
    5. }
    6. void Control::checkOption(int option)
    7. {
    8. if (option == 0)
    9. emit buttonConnected(0);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ..
    2. connect(contrl,SIGNAL(buttonConnected(int)),training,SLOT(informRecord(int)));
    3. ..
    To copy to clipboard, switch view to plain text mode 

  5. #4
    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: signals and slot...can i select my option ?

    Qt should send a warning to your console in case something is wrong with the connection. So be sure to have console support activated and look for errors there. Did you remember about the Q_OBJECT macro and declaring appropriate symbols as slots and signals?

  6. #5
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signals and slot...can i select my option ?

    i just debug my code on eclipse and it shows me this warnings..

    Current language: auto; currently c++
    warning: QObject::connect: Incompatible sender/receiver arguments
    QPushButton::clicked() --> Control::checkOption(int)

    Quit (expect signal SIGINT when the program is resumed)
    i am confused about one thing from very start that can the 'if' statement be placed in this way...i mean is it correct to place 'if' in this manner..

  7. #6
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signals and slot...can i select my option ?

    The signature of the slot should be either the same as the signature of the signal, or shorter. So,
    Qt Code:
    1. connect(accept,SIGNAL(clicked()),this,SLOT(checkOption(int))
    To copy to clipboard, switch view to plain text mode 
    is unacceptable.
    I'm a rebel in the S.D.G.

  8. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signals and slot...can i select my option ?

    that is what in a book "C++ GUI Programming with Qt 4, Second Edition
    by Jasmin Blanchette; Mark Summerfield " is written:

    To successfully connect a signal to a slot (or to another signal), they must have the same parameter types in the same order:

    connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
    this, SLOT(processReply(int, const QString &)));


    Exceptionally, if a signal has more parameters than the slot it is connected to, the additional parameters are simply ignored:

    connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
    this, SLOT(checkErrorCode(int)));


    If the parameter types are incompatible, or if the signal or the slot doesn't exist, Qt will issue a warning at run-time if the application is built in debug mode. Similarly, Qt will give a warning if parameter names are included in the signal or slot signatures.

  9. #8
    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: signals and slot...can i select my option ?

    I suggest you take a look at QSignalMapper, maybe you're trying to mimic what the class already does.

  10. #9
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signals and slot...can i select my option ?

    thanks every1...QSignalMapper solved it

Similar Threads

  1. [Basic question] Signals & Slot
    By GortiZ in forum Newbie
    Replies: 5
    Last Post: 1st April 2008, 10:39
  2. many signals, one slot
    By eric in forum Qt Programming
    Replies: 5
    Last Post: 24th January 2008, 07:25
  3. Signals and slot
    By rajeshclt3 in forum Newbie
    Replies: 1
    Last Post: 29th November 2007, 12:41

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.