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. Usage of QMessageBox in consol application
Forum Updated to NodeBB v4.3 + New Features

Usage of QMessageBox in consol application

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by
    #1

    Hi,

    I'm able to use QMessageBox in consol application as:

            QMessageBox msgBox;
            msgBox.setIcon(QMessageBox::Critical);
            msgBox.setWindowTitle("Error");
            msgBox.setText("file can't be less than 600 bytes!");
            msgBox.exec();
    

    But this takes 5 lines of code and to reduce the code I want to use it in form:

    QMessageBox::critical(this, "Error", "file can't be less than 600 bytes!");
    

    But in this case I get error:
    readsegy.cpp:87:9: error: no matching function for call to 'critical'
    qmessagebox.h:194:27: note: candidate function not viable: no known conversion from 'ReadSegy *' to 'QWidget *' for 1st argument

    I understand that the problem is in the first parameter this but is there a way to use QMessageBox "inline" style?

    Pablo J. RoginaP 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #6

      You can pass a nullptr if you don't have a parent.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Please_Help_me_DP 1 Reply Last reply
      4
      • Please_Help_me_DP Please_Help_me_D

        Hi,

        I'm able to use QMessageBox in consol application as:

                QMessageBox msgBox;
                msgBox.setIcon(QMessageBox::Critical);
                msgBox.setWindowTitle("Error");
                msgBox.setText("file can't be less than 600 bytes!");
                msgBox.exec();
        

        But this takes 5 lines of code and to reduce the code I want to use it in form:

        QMessageBox::critical(this, "Error", "file can't be less than 600 bytes!");
        

        But in this case I get error:
        readsegy.cpp:87:9: error: no matching function for call to 'critical'
        qmessagebox.h:194:27: note: candidate function not viable: no known conversion from 'ReadSegy *' to 'QWidget *' for 1st argument

        I understand that the problem is in the first parameter this but is there a way to use QMessageBox "inline" style?

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #2

        @Please_Help_me_D said in Usage of QMessageBox in consol application:

        is there a way to use QMessageBox "inline" style?

        Yes, using it properly :-)

        Documentation is your friend here.

        First parameter of such static method is a QWidget object, which the compiler is clearly letting you know about:

        qmessagebox.h:194:27: note: candidate function not viable: no known conversion from 'ReadSegy *' to 'QWidget *' for 1st argument

        So, could your please show the declaration of your ReadSegy class?

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        Please_Help_me_DP 1 Reply Last reply
        1
        • Pablo J. RoginaP Pablo J. Rogina

          @Please_Help_me_D said in Usage of QMessageBox in consol application:

          is there a way to use QMessageBox "inline" style?

          Yes, using it properly :-)

          Documentation is your friend here.

          First parameter of such static method is a QWidget object, which the compiler is clearly letting you know about:

          qmessagebox.h:194:27: note: candidate function not viable: no known conversion from 'ReadSegy *' to 'QWidget *' for 1st argument

          So, could your please show the declaration of your ReadSegy class?

          Please_Help_me_DP Offline
          Please_Help_me_DP Offline
          Please_Help_me_D
          wrote on last edited by
          #3

          @Pablo-J-Rogina thank you for answer. This part of documentation I don't understand how to use it. Mostly I don't understand where can I get parent in my case.
          here it is:

          class ReadSegy
          {
          private:
              QString segyFile;
              QString hdfFile;
              QStringList groupName = {"/TRACES_USTK", "/TRACES_STK", "/MODEL", "/HEADERS"};
              QFile *qFile;
              quint64 segySize, nTrc;
              hid_t file_id, group_id[2];
              htri_t objExist;
              QString segyEndian, segyFormat, txtEncoding;
              quint16_le dataFormatCode_le;
              quint16_be dataFormatCode_be;
              quint16 dataFormatCode, dataFormatBytes, nSamp;
              quint8 compressLevel;
              bool compressDataFlag;
              char txtHdr[3200];
          
          
          public:
              ReadSegy(QString segyFile, QString hdfFile, QString *txtEncoding, QString *segyEndian, QString *segyFormat, bool compressDataFlag, quint8 compressLevel); // Constructor
              void readTxtHdr(char txtHdr[]);
              void readBinHdr();
              void readTraces();
          };
          ``
          Pablo J. RoginaP 1 Reply Last reply
          0
          • Please_Help_me_DP Please_Help_me_D

            @Pablo-J-Rogina thank you for answer. This part of documentation I don't understand how to use it. Mostly I don't understand where can I get parent in my case.
            here it is:

            class ReadSegy
            {
            private:
                QString segyFile;
                QString hdfFile;
                QStringList groupName = {"/TRACES_USTK", "/TRACES_STK", "/MODEL", "/HEADERS"};
                QFile *qFile;
                quint64 segySize, nTrc;
                hid_t file_id, group_id[2];
                htri_t objExist;
                QString segyEndian, segyFormat, txtEncoding;
                quint16_le dataFormatCode_le;
                quint16_be dataFormatCode_be;
                quint16 dataFormatCode, dataFormatBytes, nSamp;
                quint8 compressLevel;
                bool compressDataFlag;
                char txtHdr[3200];
            
            
            public:
                ReadSegy(QString segyFile, QString hdfFile, QString *txtEncoding, QString *segyEndian, QString *segyFormat, bool compressDataFlag, quint8 compressLevel); // Constructor
                void readTxtHdr(char txtHdr[]);
                void readBinHdr();
                void readTraces();
            };
            ``
            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #4

            @Please_Help_me_D said in Usage of QMessageBox in consol application:

            where can I get parent in my case.

            Maybe the problem isn't where to get the parent from, but to get the proper class of parent.

            class ReadSegy
            {
            ...
            }
            

            Clearly your ReadSegy class is not a subclass of QWidget, and you already know that the 1st parameter to pass to the QMessage static method must be a Qwidget (or any of its descendents...), right?

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            Please_Help_me_DP 1 Reply Last reply
            0
            • Pablo J. RoginaP Pablo J. Rogina

              @Please_Help_me_D said in Usage of QMessageBox in consol application:

              where can I get parent in my case.

              Maybe the problem isn't where to get the parent from, but to get the proper class of parent.

              class ReadSegy
              {
              ...
              }
              

              Clearly your ReadSegy class is not a subclass of QWidget, and you already know that the 1st parameter to pass to the QMessage static method must be a Qwidget (or any of its descendents...), right?

              Please_Help_me_DP Offline
              Please_Help_me_DP Offline
              Please_Help_me_D
              wrote on last edited by
              #5

              @Pablo-J-Rogina yes, I'm beginner in C++ programming but as I understand first parameter should be subclass of QWidget. In GUI application I can pass first parameter as this but in consol app... ?

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                You can pass a nullptr if you don't have a parent.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                Please_Help_me_DP 1 Reply Last reply
                4
                • Christian EhrlicherC Christian Ehrlicher

                  You can pass a nullptr if you don't have a parent.

                  Please_Help_me_DP Offline
                  Please_Help_me_DP Offline
                  Please_Help_me_D
                  wrote on last edited by
                  #7

                  @Christian-Ehrlicher that works! thank you!

                  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