Results 1 to 2 of 2

Thread: Can I use connect statement on an if condition

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Can I use connect statement on an if condition

    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.



    Qt Code:
    1. // in main.cpp
    2.  
    3. CSplashScreen splash;
    4.  
    5. int cmdArgs = QCoreApplication::arguments().size();
    6. if(1 == cmdArgs)
    7. {
    8. splash.show();
    9. }
    10.  
    11. qApp->processEvents();
    12. QFont f = qApp->font();
    13. f.setPixelSize(12);
    14. qApp->setFont(f);
    15.  
    16. CMainWindow w;
    17. qApp->processEvents();
    18.  
    19. w.setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
    20. w.setWindowTitle("SecPod Saner");
    21. w.setFixedSize(800, 500);
    22. QObject::connect(&app, SIGNAL(messageAvailable(QString)), &w, SLOT(receiveMessage(QString)));
    23. if(1 == cmdArgs)
    24. {
    25. w.connect(&w, SIGNAL(showNwError_Splash(bool)), &splash, SLOT(serverConnectError_Msg(bool)));
    26. w.connect(&w, SIGNAL(showConfError_Splash()), &splash, SLOT(confError_Msg()));
    27. w.connect(&w, SIGNAL(sig_DontStartUI()), &splash, SLOT(onKillSplashScreen()));
    28. w.connect(&w, SIGNAL(sig_DontStartUI()), &w, SLOT(onQuit()));
    29. w.connect(&w, SIGNAL(sig_killSplashScreen()), &w, SLOT(show()));
    30. w.connect(&w, SIGNAL(sig_killSplashScreen()), &splash, SLOT(onKillSplashScreen()));
    31. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // in mainwindow.cpp
    2. if(1 == QCoreApplication::arguments().size())
    3. {
    4. connect(worker, SIGNAL(sig_AppActivated()), this, SIGNAL(sig_killSplashScreen()));
    5. }
    To copy to clipboard, switch view to plain text mode 

    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.

  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: Can I use connect statement on an if condition

    Yes but first argument always is the program name. Thus You must use code like this :
    Qt Code:
    1. // in mainwindow.cpp
    2. if(QCoreApplication::arguments().size() > 1)
    3. {
    4. connect(worker, SIGNAL(sig_AppActivated()), this, SIGNAL(sig_killSplashScreen()));
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    rawfool (26th August 2013)

Similar Threads

  1. Connect statement problem
    By Bender_Rodriguez in forum Newbie
    Replies: 4
    Last Post: 14th April 2013, 20:34
  2. Using an If condition in a QML delegate?
    By technoViking in forum Qt Quick
    Replies: 8
    Last Post: 25th August 2011, 05:26
  3. how to set wait condition
    By hema in forum Newbie
    Replies: 5
    Last Post: 25th July 2011, 08:08
  4. don`t work Condition...
    By Resager in forum Newbie
    Replies: 1
    Last Post: 6th May 2011, 18:18
  5. Sleep condition in QT
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2008, 12:07

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.