Solved Usage of QMessageBox in consol application
-
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 argumentI understand that the problem is in the first parameter this but is there a way to use QMessageBox "inline" style?
-
You can pass a nullptr if you don't have a parent.
-
@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?
-
@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(); }; ``
-
@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?
-
@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... ?
-
You can pass a nullptr if you don't have a parent.
-
@Christian-Ehrlicher that works! thank you!