PDA

View Full Version : How to set text to messageBox from a function outside of mainWindow



Choti
29th September 2016, 23:52
Hello Everyone,

I am working with Qt in order to display the text obtained from the return statement of a function.

So I have a function of type Stat init(), where Status is a typedef struct which contains code and error messages of type char *.
My function looks like this

Stat init()
{
stat msg;
msg.code = ERROR; //ERROR is a enum
if(.......)
{
msg.errorcode = "some message";
}

return msg;
}

This function is inside a .cpp file.

Now I have an another file named MainWindow.cpp.

In this file I include the header file of the above file, so that I can use stat init() function. Now I should display the msg in a messagebox like a warning or an information. Can someone give me an idea how I can set text such that it gets the information from Stat init().

Thank you.

anda_skoa
30th September 2016, 11:34
QMessageBox has some convenience static functions for that, where you basically just have to pass the text.

Cheers,
_