PDA

View Full Version : qt loading latency problem



ahmetturan
27th November 2013, 10:27
I use Qt 4.8.5 on Linux in old hardware ( 800 Mhz processor, 256 MB memory). I created Qt gui project and added QLineEdit to gui. I only added this line
ui->lineedit->setFocus(); to code. My problem is GUI frezes after I run program. If I type 'a' after I started program, 'a' was shown in lineedit after 3-4 seconds. Why it takes 3-4 seconds. How can I reduce it?

video of latency (http://tinypic.com/r/2exvr6h/5)

sorry for my English

saman_artorious
27th November 2013, 12:30
I'm afraid the problem is not relevant to setFocus() at all. State what the program does, paste your code in short if possible.

aamer4yu
27th November 2013, 12:35
ui->lineedit->setFocus();

Where did you add that line ?

ahmetturan
27th November 2013, 12:56
@saman_artorious: program does nothing. I added nothing to code only ui->lineEdit->setFocus(); to mainwindow.cpp and QLineEdit to gui.

@aamer4yu: I added source code. You can see ui->lineEdit->setFocus(); is after ui->setupUi(this);. Actually if I remove that line problem still happens.

mainwindow.cpp



#include "mainwindow.h"
#include "ui_mainwindow.h"

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

MainWindow::~MainWindow()
{
delete ui;
}

main.cpp


#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}

mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

aamer4yu
27th November 2013, 15:13
So the problem is not related to setFocus line..

May be check the number of processes running on the target... the memory seems only 256 MB and may be the cause.

ahmetturan
27th November 2013, 15:37
I wonder why flashing cursor on lineedit takes 3-4 secons. What is Qt doing in this time?

Radek
28th November 2013, 08:18
Only a guess: try to show the main window first and then pass focus to the lineEdit. When the window is created (by setupUi), it is hidden and cannot get focus. Subsequently, no part of the window can get focus. What will happen when you attempt to pass focus to a hidden window depends on the logic of Qt.

If I have hit the target, you can reimplement showEvent() in the main window and pass the focus there.

ahmetturan
3rd December 2013, 09:50
Actually problem is not setFocus(). Problem is why GUI freeze in first 3-4 seconds. What is Qt doing in this time? And what should I do reduce this?

anda_skoa
3rd December 2013, 10:24
Are you sure that your program is doing anything at that time?
Maybe some other process is hogging resources

Cheers,
_

ahmetturan
5th December 2013, 13:00
Are you sure that your program is doing anything at that time?


Yes I am sure. Because There is no code in project. Only there is one lineEdit in gui



Maybe some other process is hogging resources

_

There is no other running application in my os.

anda_skoa
5th December 2013, 13:51
A couple of ideas what you could investigate:

- add a QTimer to your program and let it call a slot in regular intervals. in the slot do some log output, e.g.QTime::currentTime(). Check if this comes as expected or is paused or signifcantly delayed. This should give you a hint if the program itself is slow/blocked or something it interacts with

- try a non-Qt program to rule out driver issues.

Cheers,
_