Results 1 to 6 of 6

Thread: QT Bact mode application doesnot execute when DISPLAY env variable not set

  1. #1
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QT Bact mode application doesnot execute when DISPLAY env variable not set

    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)

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Bact mode application doesnot execute when DISPLAY env variable not set

    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...tml#post118737
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT Bact mode application doesnot execute when DISPLAY env variable not set

    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 ,,

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Bact mode application doesnot execute when DISPLAY env variable not set

    "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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QT Bact mode application doesnot execute when DISPLAY env variable not set

    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.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. bool graphical = true;
    6. if (argc > 1) {
    7. if (strcmp(argv[1], "-batch") == 0)
    8. graphical = false;
    9. }
    10.  
    11. QApplication app(argc, argv, graphical);
    12. if (graphical) {
    13. w.show();
    14. return app.exec();
    15. }
    16. else {
    17. qDebug() << "Doing non-GUI stuff";
    18. return app.exec(); // if required
    19. // return 0; // otherwise
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to ChrisW67 for this useful post:

    Preethi7 (10th May 2012)

  7. #6
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT Bact mode application doesnot execute when DISPLAY env variable not set

    ThankYou Chris :-)

Similar Threads

  1. QT doesnot show any application output
    By Arpitgarg in forum Newbie
    Replies: 3
    Last Post: 27th March 2011, 13:45
  2. Replies: 2
    Last Post: 24th March 2010, 11:31
  3. Not able to execute in Release Mode
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 18th March 2009, 12:58
  4. How to execute an exe file from Qt application
    By maveric in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2008, 11:24
  5. Unable to execute in Debug Mode
    By Kapil in forum Installation and Deployment
    Replies: 38
    Last Post: 5th April 2006, 08:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.