PDA

View Full Version : Gui and Commandline support



Lumbricus
17th May 2016, 19:54
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).



#include "mainwindow.h"
#include <QApplication>
#include "imex.h"
#include <SpiceUsr.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

qDebug() << "";

//start with gui if not specified
bool nogui=false;

//check input arguments
for (int i=1; i<argc; i++)
{

if( strncmp(argv[i], "-nogui", 9) == 0)
{
nogui=true;
//no gui support

imex guidata;
qDebug() << "Input kernel location";
QTextStream s(stdin);
guidata.filepath_metakernel = s.readLine();
qDebug() << "Path is: " << guidata.filepath_metakernel;

QByteArray ba;
const char *c_str;

//QString -> C-String
ba = guidata.filepath_metakernel.toUtf8();
c_str = ba.data();

furnsh_c(c_str);

qDebug() << "No consol, not implemented";
qDebug() << "";
}
}
if(nogui == false)
{
qDebug() << "running gui";
//run gui
MainWindow w;
w.show();
}
return a.exec();
}


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

Lesiok
17th May 2016, 20:48
Fundamentals of C ++ : variable scope.

Lumbricus
17th May 2016, 21:01
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.

yeye_olive
17th May 2016, 22:19
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).