Results 1 to 5 of 5

Thread: Adding button to QMessageBox doesn't work

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

    Default Adding button to QMessageBox doesn't work

    I want to personalize button's labels so i do this:

    Qt Code:
    1. QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning, QString("blablabla"), QString("blablabla"), 0, this);
    2.  
    3. msgBox->addButton(QString("Option 1"), QMessageBox::Yes);
    4. msgBox->addButton(QString("Option 2"), QMessageBox::No);
    To copy to clipboard, switch view to plain text mode 
    and get such a message from compilator:
    Qt Code:
    1. Window.cpp: In member function 'void PicDevWindow::changeMode(int)':
    2. Window.cpp:268: error: no matching function for call to 'QMessageBox::addButton(QString, QMessageBox::StandardButton)'
    3. c:/Qt/4.8.0/include/QtGui/../../src/gui/dialogs/qmessagebox.h:143: note: candidates are: void QMessageBox::addButton(QAbstractButton*, QMessageBox::ButtonRole)
    4. c:/Qt/4.8.0/include/QtGui/../../src/gui/dialogs/qmessagebox.h:144: note: QPushButton* QMessageBox::addButton(const QString&, QMessageBox::ButtonRole)
    5. c:/Qt/4.8.0/include/QtGui/../../src/gui/dialogs/qmessagebox.h:145: note: QPushButton* QMessageBox::addButton(QMessageBox::StandardButton)
    6. Window.cpp:269: error: no matching function for call to 'QMessageBox::addButton(QString, QMessageBox::StandardButton)'
    7. c:/Qt/4.8.0/include/QtGui/../../src/gui/dialogs/qmessagebox.h:143: note: candidates are: void QMessageBox::addButton(QAbstractButton*, QMessageBox::ButtonRole)
    8. c:/Qt/4.8.0/include/QtGui/../../src/gui/dialogs/qmessagebox.h:144: note: QPushButton* QMessageBox::addButton(const QString&, QMessageBox::ButtonRole)
    9. c:/Qt/4.8.0/include/QtGui/../../src/gui/dialogs/qmessagebox.h:145: note: QPushButton* QMessageBox::addButton(QMessageBox::StandardButton)
    10. make[1]: *** [release/Window.o] Error 1
    11. make[1]: Leaving directory `/h/prg0233'
    12. make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 
    when i define earlier
    Qt Code:
    1. const QString label1("Tak");
    To copy to clipboard, switch view to plain text mode 
    It still doesn't work.
    Last edited by code_err; 8th February 2012 at 18:28.

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding button to QMessageBox doesn't work

    Maybe including a new before calling the constructor QMessageBox (QMessageBox::Warning...); ?

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

    Default Re: Adding button to QMessageBox doesn't work

    Sorry, of course i have new in my code, don't know how it disapeared here.

    Qt Code:
    1. QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning, QString("blablabla"), QString("blablabla"), 0, this);
    2.  
    3. msgBox->addButton(QMessageBox::Yes);
    4. msgBox->addButton(QMessageBox::No);
    To copy to clipboard, switch view to plain text mode 

    This one works but with default labels

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Adding button to QMessageBox doesn't work

    The second argument to addButton() is your problem not the QString. It should be QMessageBox::ButtonRole

  5. The following user says thank you to norobro for this useful post:

    code_err (8th February 2012)

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

    Default Re: Adding button to QMessageBox doesn't work

    Yes, it works, thanks.

Similar Threads

  1. Maximize button doesn't work
    By Morgan Cormier in forum Qt Programming
    Replies: 6
    Last Post: 24th March 2011, 19:33
  2. setchecked( true) of the radio button doesn't work
    By richardander in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2009, 17:54
  3. why doesn't the button work?
    By mattia in forum Newbie
    Replies: 18
    Last Post: 5th November 2007, 12:14
  4. On Qt4.2.2, QMessageBox doesn't resize!
    By manhds in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2006, 08:50
  5. Replies: 2
    Last Post: 1st August 2006, 10: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
  •  
Qt is a trademark of The Qt Company.