Results 1 to 8 of 8

Thread: Second Application opening QSystemTray

  1. #1
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Second Application opening QSystemTray

    I currently have an application that is using QSystemTray and works well. I now have another application that needs to open up the first application if it's minimized to the tray OR on the start bar. This is the current code I have to open it.

    Qt Code:
    1. Function
    2. {
    3. HWND hwnd=FindWindow(TITLE)
    4. ShowWindow(hwnd, SW_SHOW);
    5. if(!SetForegroundWindow(hwnd))
    6. {
    7. qWarning("Unable to find");
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    The only issue is that once it opens the entire application is WHITE and freezes. I'm guessing this is because Qt still thinks it's closed and won't show the dialog correctly. Any ideas on what's a workaround for this? Thanks!!!!
    Last edited by JediSpam; 10th December 2011 at 18:45.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    Use QtSingleApplication for your system tray app and QProcess to launch/show it from any other app.

    When your system tray app is launched using QProcess, in main() you just check if app is already running, and if it does - show it.

    something like this:
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QtSingleApplication app(argc, argv);
    4.  
    5. if (app.isRunning())
    6. {
    7. app.show();
    8. return 0;
    9. }
    10.  
    11. MyMainWidget mmw;
    12.  
    13. app.setActivationWindow(&mmw);
    14.  
    15. mmw.show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    I actually have SingleApplication on my application already with this main.cpp. What is the QProcess going to look like? Been trying some of its function but having no luck.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    Qt Code:
    1. QProcess p(this);
    2. p.start("Path/to/your/app/app.exe");
    To copy to clipboard, switch view to plain text mode 
    If main() in your app looks like the one few posts up (if app is running it shows it and bails out) then every attempt to launch the app while it's running will cause it to be shown.

  5. The following user says thank you to Spitfire for this useful post:

    JediSpam (15th December 2011)

  6. #5
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    Ok let me give that a shot. I tried something similar but will try again

  7. #6
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    From what you showed me,

    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QtSingleApplication app(argc, argv);
    4.  
    5. if (app.isRunning())
    6. {
    7. app.show(); //THIS CAN'T BE DONE
    8. return 0;
    9. }
    10.  
    11. MyMainWidget mmw;
    12.  
    13. app.setActivationWindow(&mmw);
    14.  
    15. mmw.show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    This is what I currently have tried. What happens is that a second instance of the application appears for a short second then disappears

    My Main.CPP
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QtSingleApplication app(argc,argv)
    4.  
    5. MainWindow w;
    6.  
    7. if (app.isRunning())
    8. {
    9. w.show(); //MAYBE I SHOULD TRY THIS? DOESN'T DO WHAT I WANT
    10. //app.show();
    11. return 0;
    12. }
    13.  
    14. Q_INIT_RESOURCE(tray);
    15. if (!QSystemTrayIcon::isSystemTrayAvailable()) {
    16. QMessageBox::critical(0, QObject::tr("Systray"),
    17. QObject::tr("I couldn't detect any system tray on this system."));
    18.  
    19. return 1;
    20. }
    21. QApplication::setQuitOnLastWindowClosed(false);
    22.  
    23. //MainWindow w;
    24. app.setActivationWindow(&w);
    25. w.hide();
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    External program calling
    Qt Code:
    1. s << "C:\\PATH.EXE;
    2. QProcess process(s);
    3. process.start();
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    Ok, my bad.
    I was guessing the interface.

    Quick search on google takes you here, so the correct method is
    Qt Code:
    1. void QtSingleApplication::activateWindow() [slot]
    To copy to clipboard, switch view to plain text mode 
    Read through the link above, it should help you with QtSingleApplication. It also shows you how otherwise you could solve your problem.

  9. #8
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Second Application opening QSystemTray

    ah crap i saw that slot! i didn't think it would apply for some reason

Similar Threads

  1. opening a second window
    By benlyboy in forum Newbie
    Replies: 3
    Last Post: 2nd March 2010, 04:08
  2. opening webpage using qt....
    By anupamgee in forum Qt Programming
    Replies: 8
    Last Post: 20th April 2009, 11:13
  3. Opening a new window
    By k12yp70n in forum Newbie
    Replies: 1
    Last Post: 26th March 2009, 15:31
  4. Opening a shapefile
    By peace_comp in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2008, 20:59
  5. QSystemTray stays longer than it should !
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2006, 11:37

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.