Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt C++ MessageBox
Forum Updated to NodeBB v4.3 + New Features

Qt C++ MessageBox

Scheduled Pinned Locked Moved General and Desktop
9 Posts 8 Posters 54.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wonopon12
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #2

      http://doc.qt.nokia.com/4.7/qmessagebox.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        durgeshK
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bittoo
            wrote on last edited by
            #5

            Hi PPl
            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);
            msgBox.setDefaultButton(QMessageBox::Save);
            int ret = msgBox.exec();@
            "For More...":http://harmattan-dev.nokia.com/docs/library/html/qt4/qmessagebox.html#Icon-enum

            Regards,
            Manoj Kumar Panwar,

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              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.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bittoo
                wrote on last edited by
                #7

                Ok JKSH :)

                Regards,
                Manoj Kumar Panwar,

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Djay96
                  wrote on last edited by
                  #8

                  thanks

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hemal
                    wrote on last edited by
                    #9

                    why was the post not marked as SOLVED then

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved