March 23, 2012

DerManu DerManu
Lab Rat
509 posts

statusBar::showMessage causes max processor load - report bug/patch qt?

 

Hi there,
observe:

  1.   ui->statusBar->showMessage("hello", 4000);
  2.   ui->statusBar->showMessage("", 1);

Now start top or htop. Funny eh? One core is busy performing an infinite loop (while the gui stays responsive).
I came across this behaviour when I was too lazy to implement an additional “clearMessage” signal in a class that needs to communicate with the statusBar. So I figured I’d be damn smart and just let it show an empty message with timeout 1 (millisecond), so it’ll properly clear right at the next event loop cycle. It bit me.

I’ve looked at qstatusbar.cpp [qt.gitorious.org], and the problem’s source is that they’re handling the timeout really strange. They have a QTimer member (d->timer) which is created and deleted when showMessage/clearMessage is called. The timer timeout signal is connected to clearMessage. The problem is, that when you set an empty string, while another non-empty string is still in its showing interval, the timer never gets deleted. Because clearMessage immediately returns when the string is empty – without even checking whether there’s a timer to delete. So basically you’ve got this rabid 1ms-timer having a party in the event loop.

Now: Would you consider this a Qt bug or is it my fault for „misusing showMessage“ (although the docs don’t warn me)? If so, is it any use reporting this? I mean I’m sure there are thousands of reports waiting to get fixed. On the other hand all you’d need is to either not only check whether the string is empty, but also whether the d->timer is 0. Or just d->timer->setSingleShot(true). Or better yet, quit this nonsense d->timer business, and just call QTimer::singleShot(timeout, this, SLOT (clearMessage())) in showMessage.
Further, do I need a gitorious account to report a bug or even submit a patch or is there a way to do it anonymously (with proper patch inspection before applying it, obviously, but that should happen anyway)?

6 replies

March 23, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Please report [qt-project.org], this clearly looks like a bug to me. Don’t forget to link the bug report here (and this thread in the bug report).

If you already have a solution attach it to the bug report or contribute [wiki.qt-project.org] directly.

March 23, 2012

DerManu DerManu
Lab Rat
509 posts

There it is:
https://bugreports.qt-project.org/browse/QTBUG-24948

Looked into getting a setup ready for contributing but they’re certainly not interested in making it easy for new contributers, so I just posted the diff in the bugreport. Let’s see what happens.

March 24, 2012

Jeroentje@home Jeroentje@ho..
Dinosaur Breeder
851 posts

Well guys, saying this is a bug is a bit strong. The program doesn’t crash and why would anyone setup a empty message in the status bar. I must admit it doesn’t look good and they should protect it better. On the other hand you should have used 0 as the timeout. That would clear the statusbar instantly without a timeout.

 Signature 

Greetz, Jeroen

March 25, 2012

DerManu DerManu
Lab Rat
509 posts

Still, it’s unintended behaviour with potentially really bad consequences. And as you can see, there’s at least one guy that triggered it ;).
If I hadn’t noticed it right away, but a week in the future (100% cpu load isn’t that obvious on a quadcore, but what would a client with a singlecore experience?) it would have been very tough to trace, since even valgrind profiling couldn’t pinpoint it, just showing the QApplication::exec() as the trouble function.

March 25, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts
Jeroentje@home wrote:
Well guys, saying this is a bug is a bit strong. The program doesn’t crash and why would anyone setup a empty message in the status bar. I must admit it doesn’t look good and they should protect it better. On the other hand you should have used 0 as the timeout. That would clear the statusbar instantly without a timeout.

Everything that does not work as intended is a bug – and this cleary does not work as intended.

March 26, 2012

rich rich
Lab Rat
37 posts

DerManu wrote:
There it is:
https://bugreports.qt-project.org/browse/QTBUG-24948

Looked into getting a setup ready for contributing but they’re certainly not interested in making it easy for new contributers, so I just posted the diff in the bugreport. Let’s see what happens.

Actually, getting set up as a contributor is pretty simple, and there’s lots of docs on the wiki at http://wiki.qt-project.org/ your diff in the bug tracker cannot be used since unlike the gerrit system used for contributions, it doesn’t ensure you’ve agreed to the contributor agreement etc.

 
  ‹‹ QT with ODBC Driver cant connect to MSSQL      QStandardItem::setData takes too much time ››

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