Minimizing Application to Tray

Page  
2

March 13, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Ok, as I use win32 functions, it’s n9ot portable :-) but it works on windows….

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 16, 2011

khalidmushtaq65 khalidmushta..
Lab Rat
40 posts

I started the debugger on and when I minimize application it displays following error..

(Internal error: pc 0×111 in read in psymtab, but not in symtab.)

When I close application, it shows no error and hides the application to tray..

March 16, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

Just a small advice, what I will do in your case. Why don’t remove from the windows the minimize button, leaving only the close, that works fine? Two buttons that do the same thing can confuse the user, not ?

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

March 17, 2011

khalidmushtaq65 khalidmushta..
Lab Rat
40 posts

ya.. nice advice:-)

March 17, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

I had the same problem with a windowless device… Decided for this solution :)

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

June 19, 2011

manuel.gysin manuel.gysin
Lab Rat
3 posts

To remove the button is no solution…
Here is a dirty hack, but it works.

  1. void MainWindow::changeEvent(QEvent *e)
  2. {
  3.     if(isMinimized())
  4.     {
  5.         show(); // The hack
  6.         slotToggleVisibility(); // Your tray icon code
  7.     }
  8. }

August 12, 2011

Ryan Ryan
Lab Rat
2 posts

If anyone still has this issue, the solution is to call qApp->processEvents() before calling hide(), ie.

  1. void ApplicationWindow::changeEvent(QEvent *event)
  2. {
  3.     QWidget::changeEvent(event);
  4.     if (event->type() == QEvent::WindowStateChange)
  5.     {
  6.         // make sure we only do this for minimize events
  7.         if ((e->oldState() != Qt::WindowMinimized) && isMinimized())
  8.         {
  9.             qApp->processEvents();
  10.             hide();
  11.             event->ignore();
  12.         }
  13.     }
  14. }

The test for the old state is probably unnecessary, but can’t hurt.

If this doesn’t help in your particular situation, try calling hide from a single-shot timer, so that the call is outside the minimize event handler:

  1. void ApplicationWindow::changeEvent(QEvent *event)
  2. {
  3.     QWidget::changeEvent(event);
  4.     if (event->type() == QEvent::WindowStateChange)
  5.     {
  6.         // make sure we only do this for minimize events
  7.         if ((e->oldState() != Qt::WindowMinimized) && isMinimized())
  8.         {
  9.             QTimer::singleShot(0, this, SLOT(hide()));
  10.             event->ignore();
  11.         }
  12.     }
  13. }

August 12, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi Ryan,

take care if you call qApp->processEvents(), as you reopen the event queue and it might happen that an event, that should be worked on after you finished is processed now. I don’t say never do it, but do it with care and always remember, synchronous workflow is broken up here.

Even a deleteLater might be processed so an object can be deleted, where you expect it not to be deleted.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

August 15, 2011

Ryan Ryan
Lab Rat
2 posts

Yep, that’s why I gave the second block of code (which I’ve just realised had the processEvents() call still in it – it wasn’t meant to be there)

Page  
2

  ‹‹ "_Z9qBadAllocv could not be located in the dynamic link library QtCore4.dll"      Resize a dialog box ››

You must log in to post a reply. Not a member yet? Register here!