0

I've been working on a Qt C++ application that deals with video processing. It usually takes a long time so that user would start the process and minimize the window to wait.

Now I'm encountering the problem that user cannot be alerted when the process is finished. I can show a QMessageBox within the application in the foreground. However there is no message that can actively notify the user when he minimizes the application and works on other stuff.

This notification doesn't have to be a pop-up. It could even be blinking in the taskbar. Any suggestions would be appreciated.

Thanks in advance!

EDIT:

I appreciate every one's quick and detailed response. QMessageBox and QSystemTrayIcon are two possible solutions. I do partially solve my problem by the following code:

HWND hHandle = FindWindow(NULL,L"nameOfYourApplication");
FLASHWINFO pf;
pf.cbSize = sizeof(FLASHWINFO);
pf.hwnd = hHandle;
pf.dwFlags = FLASHW_TIMER|FLASHW_TRAY; // (or FLASHW_ALL to flash and if it is not minimized)
pf.uCount = 8;
pf.dwTimeout = 75;
FlashWindowEx(&pf);

This will flash the taskbar. Once again, thanks so much for every one involved in this!

3 Answers3

2

You can use QSystemTrayIcon to show the messagex from the taskbar tray.

Use method QSystemTrayIcon::showMessage to fire a notification.

And with QSystemTrayIcon::setVisible(bool visible) you can show/hide the icon in the tray.

Use QSystemTrayIcon::setIcon to setup required icon.

Max Go
  • 2,092
  • 1
  • 16
  • 26
  • +1 for you, it can be a solution, but I posted answer which solves problem with hidden messagebox when app is hidden. – Jablonski Sep 26 '14 at 16:07
  • I use the same idea, however it is implemented with windows api instead of qt api. Thanks though! I don't have enough reputation to support your answer. I wish I have. – coder_in_the_wild Sep 27 '14 at 02:48
1

Inside QMainWindow:

ShowWindow((HWND)this->winId(), SW_MINIMIZE);//#include <windows.h>
ShowWindow((HWND)this->winId(), SW_MAXIMIZE);
showMessageBox();
Marian
  • 104
  • 1
  • 6
0

QSystemTrayIcon is normal solution, but you should add new code, and many apps in trays can be annoying, so you should be sure that your app really need icon tray. And back to the original question:

If you use this:

QMessageBox::information(this,"title","text");

then your QMessageBox will be really hidden as your window, but when you use this:

qApp->setQuitOnLastWindowClosed(false);
QMessageBox box;
box.setText("text");
box.exec();

Or this for example:

qApp->setQuitOnLastWindowClosed(false);
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle("title");
box->setText("text");
box->show();

Then you get this QMessageBox if your window is hidden or not.

Why we need qApp->setQuitOnLastWindowClosed(false);? By default, a Qt application closes when the last window is closed, so if you close this box but windows will be hidden, then app will be closed. With setQuitOnLastWindowClosed it will run normal.

Edit:

QMessageBox *box = new QMessageBox;
box->setWindowTitle("title");
box->setText("text");
box->show();
this->showNormal();
Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • well, I'm not sure on 100% that modal call of QMessageBox when the app is minimized will be showed to the user and "actively notify" user. I think it will be needed to call additionally something like QWindow::raise() on MainWindow of the app. – Max Go Sep 26 '14 at 16:22
  • @N1ghtLight I tested it, and it was normal, but I impoved my answer,with some useful thing. If you are interested in this, you can see it. – Jablonski Sep 26 '14 at 16:30
  • Sorry, I've tried on Win 8.1, but it doesn't work. Message box appears, but minimized application doesn't rise and doesn't actively notify user. Also it looks like, because you suggest to use setQuitOnLastWindowClose, you think that main application window is going to be hide, but author wrote that application is just minimized to the taskbar. – Max Go Sep 26 '14 at 16:43
  • @N1ghtLight Sorry, I did't understand you. Of course, if window is minimized and you want show it, you should call `this->showNormal();` See my edit. Is it normal now? – Jablonski Sep 26 '14 at 16:51
  • Call of this->showNormal() doesn't help too. On what OS are you testing? On Windows 8.1 if I run last your code example, where your last code snippet is trigerred by QTimer after 5 seconds app is launch, then: 1. App window is opened. 2. I minimzed the app to the task bar and other apps windows are active now. 3. After 5 seconds my test app starts blinking in the task bar, but it's not opened, etc, I don't see the message, I need to click on it in task bar to see the message. Do you have some another behavior? – Max Go Sep 26 '14 at 16:59
  • @N1ghtLight `timer->start(4000);` connected to `echo()` slot which contains same code. 1. App opened. 2. I minimize it, slot called and I get the box and window become normal, there is no any blinking, all works. Win 7, Qt 5.2.0 – Jablonski Sep 26 '14 at 17:07
  • hmmm ... well, for me it doesn't work, and I was pretty sure that it doesn't work :) maybe, it depends on some circumstance or really on platform. Also from my experience any non usual usage of QMessageBox in cross platform app will bring some portion of headache :) – Max Go Sep 26 '14 at 17:20
  • Check this - http://stackoverflow.com/questions/7817334/qt-correct-way-to-show-display-raise-window ... – Max Go Sep 26 '14 at 17:25
  • @N1ghtLight Do `widget->raise();`and `widget->show();` works properly in your Windows? If so, I improve my answer with this code. – Jablonski Sep 26 '14 at 17:27
  • No, it doesn't work too for me, I've already tried... as you can see by link to another question any answer is not accepted. This is "black hole" in Qt :) – Max Go Sep 26 '14 at 17:30
  • It actually doesn't solve the problem. It will show the window, however only if you are in the desktop. If you are in another application, the window is shown in the desktop. – coder_in_the_wild Sep 27 '14 at 02:46