PDA

View Full Version : The program start slowly with repaint problem



SABROG
20th May 2009, 14:20
In attach you may view empty window when programm starting, after few second his redraw normal.

I fix this by add this in constructor and remove show() from main.cpp:



QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection);


In mainwindow consturctor i create 2 instances QHttp my be in this problem?

caduel
20th May 2009, 21:41
Please rephrase that, give us more details and perhaps some code.
(Sorry, but I fail to understand what your problem is, I don't know what you are trying to do or where QHttp comes into play.)

SABROG
21st May 2009, 07:55
I try say, what i don't want see empty window while program running. Inside constructor i create 2 instances QHttp.

faldzip
21st May 2009, 08:35
can you show us you constructors code?

SABROG
21st May 2009, 09:55
SpoList::SpoList(QWidget *parent)
: QMainWindow(parent), twCountries(0), progressDialog(this)
{
//QErrorMessage::qtHandler();
setupUi(this);
readSettings();
QDateEdit *dateEdit = new QDateEdit(this);
QDate earlerDate = QDate::currentDate();
earlerDate = earlerDate.addDays(-10);
dateEdit->setDate(earlerDate);
dateEdit->setCalendarPopup(true);
toolBar->addWidget(dateEdit);

http = new QHttp(this);

connect(http, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(requestStarted(int)), this, SLOT(httpRequestStarted(int)));
connect(http, SIGNAL(dataReadProgress(int, int)),
this, SLOT(updateDataReadProgress(int, int)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
connect(http, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
this, SLOT(slotAuthenticationRequired(const QString &, quint16, QAuthenticator *)));

connect(&progressDialog, SIGNAL(canceled()), http, SLOT(abort()));
http->setHost(host);

spohttp = new QHttp(this);
connect(spohttp, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpSpoRequestFinished(int, bool)));
connect(spohttp, SIGNAL(requestStarted(int)), this, SLOT(httpSpoRequestStarted(int)));
connect(spohttp, SIGNAL(dataReadProgress(int, int)),
this, SLOT(updateSpoDataReadProgress(int, int)));
connect(spohttp, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readSpoResponseHeader(const QHttpResponseHeader &)));
connect(spohttp, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
this, SLOT(slotSpoAuthenticationRequired(const QString &, quint16, QAuthenticator *)));
spohttp->setHost(host);
screenCenter();
QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection);
}

caduel
21st May 2009, 11:11
What would be more interesting is what you do want to see, not what you don't.

You have two choices:
* make the window not appear at all til some condition is met (e.g. your QHttp instances have connected, finished or whatever)
* make the window appear with content right away (call the necessary stuff like show, screenCenter etc before creating the QHttp stuff?)

HTH

SABROG
21st May 2009, 13:16
This not help. Only invokeMethod helps.



SpoList::SpoList(QWidget *parent)
: QMainWindow(parent), twCountries(0), progressDialog(this)
{
http = new QHttp(this);

connect(http, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(requestStarted(int)), this, SLOT(httpRequestStarted(int)));
connect(http, SIGNAL(dataReadProgress(int, int)),
this, SLOT(updateDataReadProgress(int, int)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
connect(http, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
this, SLOT(slotAuthenticationRequired(const QString &, quint16, QAuthenticator *)));

connect(&progressDialog, SIGNAL(canceled()), http, SLOT(abort()));

http->setHost(host);

spohttp = new QHttp(this);
connect(spohttp, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpSpoRequestFinished(int, bool)));
connect(spohttp, SIGNAL(requestStarted(int)), this, SLOT(httpSpoRequestStarted(int)));
connect(spohttp, SIGNAL(dataReadProgress(int, int)),
this, SLOT(updateSpoDataReadProgress(int, int)));
connect(spohttp, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readSpoResponseHeader(const QHttpResponseHeader &)));
connect(spohttp, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
this, SLOT(slotSpoAuthenticationRequired(const QString &, quint16, QAuthenticator *)));
spohttp->setHost(host);
setupUi(this);
readSettings();
QDateEdit *dateEdit = new QDateEdit(this);
QDate earlerDate = QDate::currentDate();
earlerDate = earlerDate.addDays(-10);
dateEdit->setDate(earlerDate);
dateEdit->setCalendarPopup(true);
toolBar->addWidget(dateEdit);
screenCenter();
show();
}


I comment all and leave only setupUi() problem not gone, something wrong inside core. May be plugins.

faldzip
21st May 2009, 13:40
My advice would be to remove the QHttp initilization, connections etc from MainWindow constructor, and put it in some other method, lets say init(). Then make the init() method as a slot and connect to some button or timer or whatever, show the window (in main() not in constructor), then push the button conected to init(). It will make you sure that window is painted and everything is ok, so you can then run the QHttp stuff.

SABROG
21st May 2009, 14:49
I post early what i remove all from constructor and problem not gone.

Profiler say what cpu eat this method:
ZN14QWaitCondition4waitEP6QMutexm 97,64 3 8451235,51

I don't use QWaitCondition and QMutex inside program. With other programs i don't have this problem.

May be network get this effect. This code from qeventdispatcher_win.cpp


void SocketAsyncHandler::run()
{
do {
mutex.lock();

while (!supposedToDie && sockets.isEmpty()) {
cond.wait(&mutex);
}

faldzip
21st May 2009, 16:13
So I think that you can also check the callers of those methods and than investigate what causes this slow down.

SABROG
21st May 2009, 16:50
Callers? QApplication.exec() :)