PDA

View Full Version : QTimer is stopped while screen is locked



Fred
10th July 2015, 14:03
I have just switched from Qt 4 to Qt 5.5 and found out that the behaviour of QTimer is different. When the session is automatically locked after 10 minutes of idle (Xubuntu / Light Locker) QTimer stops working and my application also stops working until the session is unlocked and the desktop appears.

I have tested the behaviour with this small app:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
}

void MainWindow::update(){
ui->textEdit->append(QTime::currentTime().toString("hh:mm:ss"));
}

And the timer stops after the session is locked:
13:43:01
13:43:02
13:43:03 <-- Session locked
13:43:36 <-- Session unlocked
13:43:37

Is this a bug or new feature? Qt 4.x works fine but Qt 5.5 do not. Is there a way to workaround this behaviour because my application also stop working while the session / screen is locked?

anda_skoa
10th July 2015, 14:57
That is strange.

Can you try writing the timestamp to a file instead of appending to the text edit?
Maybe also try doing the same with a QCoreApplication and no UI at all, just to see if that has any impact.

Cheers,
_

Fred
10th July 2015, 16:47
Thank you for your reply.

That is strange.
Can you try writing the timestamp to a file instead of appending to the text edit?

This make no difference, the QTimer will be stopped when the session is locked.



Maybe also try doing the same with a QCoreApplication and no UI at all, just to see if that has any impact.

Okay this works like expected and the QTimer works in the background. Is this a bug which should be reported?

anda_skoa
10th July 2015, 18:43
Okay this works like expected and the QTimer works in the background. Is this a bug which should be reported?
Sounds like it.
Nothing should really block the main event loop.

Would be interesting to try to narrow it further down.
Does it also happen when the application object is a QGuiApplication but there is no window.
If that works, does it also work with a QApplication and no window.
Or with a QGuiApplication and a plain QWindow.

Cheers,
_

wysota
10th July 2015, 20:06
Could it be a "feature" of the desktop environment that it sigstops all gui apps when the session is locked?

ChrisW67
10th July 2015, 22:16
I would think that an exceptionally dumb "feature" Which would affect the Qt 4 version equally.

wysota
10th July 2015, 23:08
So would I but then I wouldn't expect a screen locker to affect event flow of other applications.