Results 1 to 5 of 5

Thread: Problem with QPushButton setDisabled SLOT

  1. #1
    Join Date
    Sep 2011
    Posts
    86
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Problem with QPushButton setDisabled SLOT

    I was trying to find solution on forum but couldn't. The problem is i connected SIGNAL from QComboBox with QPushButton SLOT. I want it to be disabled after changing item from combo list but it doesn't work. When i connect this same SIGNAL with qApp quit() SLOT it works.

    Qt Code:
    1. QObject::connect(&combo, SIGNAL(activated(int)), &button, SLOT(setDisabled()));
    To copy to clipboard, switch view to plain text mode 

    Button inherits this SLOT from QWidget but i don't know why in the Qt Designer i cannot see this SLOT.

    Qt Code:
    1. #include <QApplication>
    2. #include <QtCore>
    3. #include <QtGui>
    4.  
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8.  
    9. QWidget window;
    10. QVBoxLayout *layout = new QVBoxLayout;
    11.  
    12. list << "jeden" << "dwa" << "trzy" << "cztery" << QString::fromUtf8("pięć");
    13.  
    14. QComboBox combo;
    15. combo.addItems(list);
    16.  
    17. QPushButton button(QString::fromUtf8("Wyłącz się do cholery"));
    18.  
    19. window.setLayout(layout);
    20.  
    21. layout->addWidget(&combo);
    22. layout->addWidget(&button);
    23.  
    24. QObject::connect(&combo, SIGNAL(activated(int)), &button, SLOT(setDisabled(bool)));
    25. QObject::connect(&button, SIGNAL(clicked()), qApp, SLOT(quit()));
    26.  
    27. window.show();
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    it is complete main.cpp

    Ok, what is wrong with this code?
    Last edited by code_err; 8th October 2011 at 18:29.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with QPushButton setEnabled SLOT

    There are two issues with your connect statement:
    1) Your parameters mismatch, read here about signal-slot connections.
    And second
    2) you can't use values in the connect (you can use only types) so you can't write false just bool

    LE: i see you edited your post
    with quit it works because the int parameter is not needed (since quit doesn't take any parameters the int is ignored) but the setDisable slot needs to be called with one bool parameter.

  3. #3
    Join Date
    Sep 2011
    Posts
    86
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem with QPushButton setEnabled SLOT

    So i need to write my own SIGNAL? and will have to write a new class just for this little thing?

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with QPushButton setEnabled SLOT

    Any way it's better to have your "gui"/widget encapsulated into a class (for example see the "pattern" for ui usage).
    So you can derive a class from QWidget and add combo and button (and other widgets you need) and code the gui functionality you need (by coding signals, slots, make the needed connections) so that the object will be usable.

  5. #5
    Join Date
    Sep 2011
    Posts
    86
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem with QPushButton setDisabled SLOT

    Thanks for quick response.

Similar Threads

  1. QPushButton Signal and QFrame show as a Slot
    By Prophet in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2011, 16:25
  2. qwtplot::setEnabled(false) ignored?
    By liversedge in forum Qwt
    Replies: 1
    Last Post: 7th August 2011, 21:07
  3. Replies: 2
    Last Post: 13th December 2010, 11:31
  4. connect a qpushbutton a slot
    By Lycus HackerEmo in forum Newbie
    Replies: 13
    Last Post: 29th March 2010, 10:14
  5. SLOT and QPushButton
    By mickey in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2006, 07:46

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.