PDA

View Full Version : Can I use connect statement on an if condition



rawfool
22nd August 2013, 14:56
I'm trying to solve a condition where I shouldn't show splash screen on startup of reboot. But if application is launched by clicking on shortcut icon, then the splash screen has to be shown.

So for this to work, I'm trying to use invoke application using commandline arguments in my installer script. And I set the condition as - if number of argument(s) is 1 then show splash, otherwise don't show splash.





// in main.cpp

CSplashScreen splash;

int cmdArgs = QCoreApplication::arguments().size();
if(1 == cmdArgs)
{
splash.show();
}

qApp->processEvents();
QFont f = qApp->font();
f.setPixelSize(12);
qApp->setFont(f);

CMainWindow w;
qApp->processEvents();

w.setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
w.setWindowTitle("SecPod Saner");
w.setFixedSize(800, 500);
QObject::connect(&app, SIGNAL(messageAvailable(QString)), &w, SLOT(receiveMessage(QString)));
if(1 == cmdArgs)
{
w.connect(&w, SIGNAL(showNwError_Splash(bool)), &splash, SLOT(serverConnectError_Msg(bool)));
w.connect(&w, SIGNAL(showConfError_Splash()), &splash, SLOT(confError_Msg()));
w.connect(&w, SIGNAL(sig_DontStartUI()), &splash, SLOT(onKillSplashScreen()));
w.connect(&w, SIGNAL(sig_DontStartUI()), &w, SLOT(onQuit()));
w.connect(&w, SIGNAL(sig_killSplashScreen()), &w, SLOT(show()));
w.connect(&w, SIGNAL(sig_killSplashScreen()), &splash, SLOT(onKillSplashScreen()));
}





// in mainwindow.cpp
if(1 == QCoreApplication::arguments().size())
{
connect(worker, SIGNAL(sig_AppActivated()), this, SIGNAL(sig_killSplashScreen()));
}


Is this correct way to hide connect statements under if condition ??
I find it working though, but I'm unsure if I can do this way.

Kindly help. Thank you.

Lesiok
22nd August 2013, 16:49
Yes but first argument always is the program name. Thus You must use code like this :

// in mainwindow.cpp
if(QCoreApplication::arguments().size() > 1)
{
connect(worker, SIGNAL(sig_AppActivated()), this, SIGNAL(sig_killSplashScreen()));
}