Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt creator, error message

I am a little rusty with QT but I've had to use it for projects before.

I was wondering if I could make a pop-up window, a small window with it's height/width disabled so the user can't expand it. It should also lock the screen until they press a button on this window.

I could do all of this in a separate class, but I was wondering. Are there any built-in QT classes that have a little popup like this that I could just modify? I mean making a class just for an error message seems to me a little wasteful. I'm trying to keep the project small.

But if a class is required to be made in order to accomplish this, that is fine. The only problem is I have no clue how to lock the application windows so that you have to do something one window before you can go back to the main application.

I'm not asking for someone to type out all this code for me, just give me a link or something. I've looked for it but I couldn't find it. Cheers.

like image 229
Gabriel Avatar asked Apr 04 '12 18:04

Gabriel


3 Answers

QMessageBox messageBox;
messageBox.critical(0,"Error","An error has occured !");
messageBox.setFixedSize(500,200);

The above code snippet will provide the required message box.

like image 165
Soumya Kundu Avatar answered Nov 15 '22 21:11

Soumya Kundu


For a simple error message, I would suggest you look into the QMessageBox (the documentation contains little example that should show you how to easily achieve what you need), which is modal too. Using a QDialog for displaying a simple error message is possible too, but maybe too much for such a simple task.

like image 26
talnicolas Avatar answered Nov 15 '22 21:11

talnicolas


I believe what you are looking for is something along the lines of QDialog. Dialogs can be modal or nonmodal. Modal dialogue "block" interaction with the calling window until the Dialog window has been handled.

You can either subclass QDialog or check to see if one of the default dialog classes will be enough for what you need.

like image 41
nqe Avatar answered Nov 15 '22 21:11

nqe