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.
Code:
Function
{
HWND hwnd=FindWindow(TITLE)
ShowWindow(hwnd, SW_SHOW);
if(!SetForegroundWindow(hwnd))
{
qWarning("Unable to find");
}
}
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!!!!
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:
Code:
int main(int argc, char **argv)
{
QtSingleApplication app(argc, argv);
if (app.isRunning())
{
app.show();
return 0;
}
MyMainWidget mmw;
app.setActivationWindow(&mmw);
mmw.show();
return app.exec();
}
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.
Re: Second Application opening QSystemTray
Code:
p.start("Path/to/your/app/app.exe");
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.
Re: Second Application opening QSystemTray
Ok let me give that a shot. I tried something similar but will try again
Re: Second Application opening QSystemTray
From what you showed me,
Code:
int main(int argc, char **argv)
{
QtSingleApplication app(argc, argv);
if (app.isRunning())
{
app.show(); //THIS CAN'T BE DONE
return 0;
}
MyMainWidget mmw;
app.setActivationWindow(&mmw);
mmw.show();
return app.exec();
}
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
Code:
int main(int argc, char **argv)
{
QtSingleApplication app(argc,argv)
MainWindow w;
if (app.isRunning())
{
w.show(); //MAYBE I SHOULD TRY THIS? DOESN'T DO WHAT I WANT
//app.show();
return 0;
}
Q_INIT_RESOURCE(tray);
QObject::tr("I couldn't detect any system tray on this system."));
return 1;
}
//MainWindow w;
app.setActivationWindow(&w);
w.hide();
return app.exec();
}
External program calling
Code:
s << "C:\\PATH.EXE;
QProcess process(s);
process.start();
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
Code:
void QtSingleApplication::activateWindow() [slot]
Read through the link above, it should help you with QtSingleApplication. It also shows you how otherwise you could solve your problem.
Re: Second Application opening QSystemTray
ah crap i saw that slot! i didn't think it would apply for some reason :mad: