PDA

View Full Version : QT Bact mode application doesnot execute when DISPLAY env variable not set



Preethi7
9th May 2012, 12:22
Hello,

I ve a QT application running both interactively and in batch mode built in Solaris and Linux too . When the application is started , by default QMainWindow is created (but not shown )and the arguments passed are validated (if any )and then it is checked whether the application is to be run interactively or in batch mode.

If the environment variable DISPLAY is set then there is no issues , everything works fine. But if the env variable DISPLAY is ot set then the batch mode also doesnt work.. Is there any work aroud for this issue ?? (other than modifying the design of the application)

amleto
9th May 2012, 12:50
lol. Where did I put that crystal ball?


edit: oh god, another one that likes to cross post, typos and all.
http://www.qtforum.org/article/37907/qt-bact-mode-application-doesnot-execute-when-display-env-variable-not-set.html#post118737

Preethi7
9th May 2012, 13:18
Hi Amulet,,

Sorry for crossposting but it would have sounded better if you have spent some time in finding a solution to my issue, rather than finding that i cross posted and with typos (I am a learner and its a new thing for me and i am so eager to find some workaround to solve this issue ).
My issue is ,

I have a QT application that runs both in interactive mode wit GUI and in Batch mode without GUI.
When the binary is invoked , it starts the application by creating a QMainWindow
After this only the application validates the arguments passed in command line when invoking the binary
checks whether to execute in interactive mode i.e with GUI or batch mode i.e without GUI (-batch option will be provided in the command line if the user wanst to runt the application in batch mode)

Now, if the application executes fine in both Batch mode (without GUI) and interactive mode (with GUI) when the environment variable DISPLAY is set.

But some users dont bother to set the DISPLAY variable when they want to execute the tool in batch mode (without GUI). In that scenario the tool doesnt work as it tries to create QMainwindow , but the DISPLAY is not set .

I think i made it clear now ,,

amleto
9th May 2012, 13:41
"it would have sounded better if you have spent some time in finding a solution to my issue"

How is anyone meant to do that with the information you have given?

You have a problem with DISPLAY. Great, let me guess what is wrong INSIDE your code whilst you have shown NONE of your code. See the problem?

ok, now read my sig.

ChrisW67
9th May 2012, 23:32
If you created a (default) QApplication or QMainWindow object then Qt requires the ability to do graphical things. On Linux/UNIX this requires X11 and the DISPLAY variable, which is how that graphical environment is found. If you do not want to be dependent on X11 then you need to avoid creating anything that needs it before you decide you want to use the graphical environment. Nothing stops you checking command line arguments before you create the QApplication/QMainWindow or QCoreApplication/non-GUI worker object. The exact arrangement can vary but it really is quite straightforward.



#include <QtGui>

int main(int argc, char **argv)
{
bool graphical = true;
if (argc > 1) {
if (strcmp(argv[1], "-batch") == 0)
graphical = false;
}

QApplication app(argc, argv, graphical);
if (graphical) {
QMainWindow w;
w.show();
return app.exec();
}
else {
qDebug() << "Doing non-GUI stuff";
return app.exec(); // if required
// return 0; // otherwise
}
}

Preethi7
10th May 2012, 06:22
ThankYou Chris :-)