Results 1 to 7 of 7

Thread: Slots connection !

  1. #1
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Slots connection !

    Hi all ! I'm having some troubles with connecting a comboBox and a function...

    in .h
    Qt Code:
    1. private slots:
    2. /*! Call a quit function. */
    3. void slotQuit();
    4.  
    5. /*! Call a function which can show an AboutForm. */
    6. void slotAbout();
    7.  
    8. /*! Call a function which update the view when the comboBox is changed. */
    9. void slotCurrentSelectionChanged();
    To copy to clipboard, switch view to plain text mode 

    in .cpp
    Qt Code:
    1. ui_murefImpl::ui_murefImpl(QWidget *parent) : QMainWindow(parent)
    2. {
    3. // configuring the GUI
    4. ui.setupUi(this);
    5. // do connections
    6. connect(ui.actionQuit, SIGNAL(activated()), this, SLOT(slotQuit()));
    7. connect(ui.actionAbout, SIGNAL(activated()), this, SLOT(slotAbout()));
    8. connect(ui.comboBox, SIGNAL(activated(QString test)), this, SLOT(slotCurrentSelectionChanged()));
    9. // end
    10. }
    11.  
    12. // some code here...
    13.  
    14. void ui_murefImpl::slotCurrentSelectionChanged()
    15. {
    16. QMessageBox::information(0, "", "ok");
    17. CLinkGUI::callCurrentSelectionChanged();
    18. }
    To copy to clipboard, switch view to plain text mode 

    By default I put 2 items in the comboBox... so that I can select them but I never saw the message box with ok...

    (of course, the code compile fine... AND others slots function...)

    Thanks a lot for the one who find out the solution .

    edit: Oh, yeah, of course too, with the Designer I can add lower() function as a slot and it work perfectly...

    Qt Code:
    1. QObject::connect(comboBox, SIGNAL(activated(QString)), MainWindow, SLOT(lower()));
    To copy to clipboard, switch view to plain text mode 

    this line is added in ui_muref.h (generated from uic/moc tools)
    Last edited by agent007se; 18th July 2006 at 22:41.

  2. #2
    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: Slots connection !

    Quote Originally Posted by agent007se
    connect(ui.comboBox, SIGNAL(activated(QString test)), this, SLOT(slotCurrentSelectionChanged()));
    You can't put parameter names in SIGNAL and SLOT macros.

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

    agent007se (18th July 2006)

  4. #3
    Join Date
    Jun 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slots connection !

    Correct ! Just saw it but I thank you anyway because of your high speed replies !

  5. #4
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slots connection !

    and actually you shouldn't even have a parameter at all in the signal when the slot doesn't receive one - but as long as the signal has more parameters than the slot and not vice versa it will work nevertheless.

  6. #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: Slots connection !

    Quote Originally Posted by mikro
    and actually you shouldn't even have a parameter at all in the signal when the slot doesn't receive one
    Hmm... Why not?

  7. #6
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Slots connection !

    because it's ugly
    but as i said it works nevertheless, it just might become confusing

  8. #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: Slots connection !

    Quote Originally Posted by mikro
    because it's ugly
    Ugly? Why? Are default parameters ugly? Would it be better (less ugly) to have additional, completely redundant slot parameters just to have the same number of parameters as the signal?


    but as i said it works nevertheless
    Why shouldn't it work? It's behaving according to C++ specification, there is no hack in it.

    it just might become confusing
    Again, why confusing? You specify output (SIGNAL) and input (SLOT or other SIGNAL) parameters as separate groups (using different macros). I don't see anything confusing about it.

Similar Threads

  1. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28
  2. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06
  3. howto debug connection of signals and slots?
    By jh in forum Qt Programming
    Replies: 11
    Last Post: 24th February 2006, 09:30
  4. Missing slots
    By Mariane in forum Newbie
    Replies: 1
    Last Post: 5th February 2006, 01:50
  5. [QT4] threads, signals, and slots, please help.
    By ucntcme in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 14:23

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.