Qt C++ MessageBox
wonopon12 last edited by
Hello, I am just starting off as a GUI Developer for C++. I am experienced with Console Programming. I was looking for a SDK with a simple and organized environment and I found the Qt SDK :) The interfaces are so customizable and I love it! I have one question though. How can I make a MessageBox() appear? Can someone give me an example of a MessageBox() function that works with the Qt SDK. Console & GUI are different.
The Console version of MessageBox() would work like this :
MessageBox(NULL, "Hello World!", "Hi!", MB_OK | MB_ICONHAND);
What would the Qt version of MessageBox() look like? Thanks very much guys :)
vinb last edited by
durgeshK last edited by
You can use static member functions of QMessagebox like warning, error, information. Syntax of all of them are same
StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
And it is being called as follow:
QMessageBox::information(NULL, "Hello World!", "Hi!");
You can also use the 'exec()' member function of QMessageBox.
tobias.hunger last edited by
Please note that QMessageBox is in QtGui, so if you use that you will need to link against that. You also need a QApplication instead of a QCoreApplication.
I am just mentioning that since you keapt referring to console applications which usually do not need to link against QtGui.
Bittoo last edited by
Here is the sample code for message Box:
@ QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
int ret = msgBox.exec();@
Thank you for your contribution, Bittoo. However, check the date -- the question was already answered more than 2 years ago. It's best not to post in old threads. :)
Also, I recommend using the official Qt Project documentation for most purposes: http://qt-project.org/doc/qt-5.0/qtwidgets/qmessagebox.html -- Nokia's documentation is outdated now.
Bittoo last edited by
Ok JKSH :)
Djay96 last edited by
hemal last edited by
why was the post not marked as SOLVED then