Results 1 to 4 of 4

Thread: Gui and Commandline support

  1. #1
    Join Date
    Oct 2015
    Posts
    33
    Thanks
    14
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question Gui and Commandline support

    Hey guys,

    i'm making a program with a gui, due to ram and cpu specifications i need to put this program on a cluster and run it there. I cannot get gui support from the server through vpn. So im trying to make my app work as a gui or as a commandline program.

    I can start the program from command line with the command(this is on linux):
    "./imex" -> with gui
    "./imex -nogui" -> withought gui

    the thing im interested in, is the final if{nogui==false} below, why does my gui not show up on my testmachine if i run the ./imex command, if i dont run the nogui check ( the if {nogui==false} it will run fine).

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include "imex.h"
    4. #include <SpiceUsr.h>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. qDebug() << "";
    11.  
    12. //start with gui if not specified
    13. bool nogui=false;
    14.  
    15. //check input arguments
    16. for (int i=1; i<argc; i++)
    17. {
    18.  
    19. if( strncmp(argv[i], "-nogui", 9) == 0)
    20. {
    21. nogui=true;
    22. //no gui support
    23.  
    24. imex guidata;
    25. qDebug() << "Input kernel location";
    26. QTextStream s(stdin);
    27. guidata.filepath_metakernel = s.readLine();
    28. qDebug() << "Path is: " << guidata.filepath_metakernel;
    29.  
    30. const char *c_str;
    31.  
    32. //QString -> C-String
    33. ba = guidata.filepath_metakernel.toUtf8();
    34. c_str = ba.data();
    35.  
    36. furnsh_c(c_str);
    37.  
    38. qDebug() << "No consol, not implemented";
    39. qDebug() << "";
    40. }
    41. }
    42. if(nogui == false)
    43. {
    44. qDebug() << "running gui";
    45. //run gui
    46. MainWindow w;
    47. w.show();
    48. }
    49. return a.exec();
    50. }
    To copy to clipboard, switch view to plain text mode 

    can someone explain what happens with the gui if i put the mainwWindow w; w.show(); in the if-brackets?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Gui and Commandline support

    Fundamentals of C ++ : variable scope.

  3. The following user says thank you to Lesiok for this useful post:

    Lumbricus (17th May 2016)

  4. #3
    Join Date
    Oct 2015
    Posts
    33
    Thanks
    14
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Gui and Commandline support

    Thank you for the answer...man i've been looking at this dumb mistake for 2 hours. Thanks for the pointer.

    TLDR: moved the Mainwindow w; object out of the brackets so it would not get destroyed when the if{}-statement went out of scope.

  5. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Gui and Commandline support

    Notice that even with -nogui, your program is still dynamically linked with GUI libraries that need to be loaded. Are these libraries available on your cluster? If not, you should build two separate programs (a GUI application and a console application).

Similar Threads

  1. How to run Qt application from windows commandline?
    By aurora in forum Qt Programming
    Replies: 4
    Last Post: 26th April 2012, 09:36
  2. Replies: 2
    Last Post: 31st March 2011, 10:09
  3. Replies: 2
    Last Post: 30th March 2011, 10:11
  4. Design a commandline widget in Qt4?
    By Ran in forum Qt Programming
    Replies: 8
    Last Post: 7th January 2009, 04:14
  5. coding a commandLine class
    By mickey in forum General Programming
    Replies: 8
    Last Post: 27th November 2007, 09:46

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.