Slow form
-
hi,
another beginner's question that sounds more like a I'm looking for a needle in a bottle:
I have several forms, all of them are opened instantly when I click the QAction from the QToolBar from mainwindow, except one. this form is very slow; it takes two one seconds or more. any idea where to start to look for the delay? or is there a possibility to measure the exec() time?cheers
-
What r u loading in the form ? U can put some debug messages in slot and try to put message box inside slot to check whether it is quick ?
-
In the form is loaded several widgets:
pushButtons, lineEdits, labels (that takes some values from a database), one tableView (that takes some values from a database, displayed via a QSqlQueryModel, QSortFilterProxyModel), several Sql queries (the biggest is one with INSERT 40 elements when a pushButton is triggered), widgets that are originally hidden and when a RadioButton is pushed they are showed, etc.I put a qDebug() message in the mainWindow when the QAction is triggered, the message is shown on the Application Output instant, so the delay has to do with the opening form.
any idea? thank you
-
SQL queries may be the reason. Don't start the queries immediately but use a slot which you can call with, for example,
@QTimer::singleShot(0, this, SLOT(...))@If you have some experience with threads, QThreadPool or QtConcurrent, you can run the queries in a worker thread and then populate the Uİ.
-
Your answer itself proves that it is not a issue with QAction and coming to your slot. You are doing some time consuming tasks in your slots. As suggested by previous post, SQL operations could be real target of slowness. Just see whether you can move these operations to some thread and handle it.
-
hi all,
thanks for your feedback. I've been reading about QThread. this should be a powerful tool, especially when it comes to priority. I'm trying to create a separate class run the thread, but I'm not sure how to connect it to my widget (lineEdit) that should show the returned query value.
any hints?
thanks -
Hi,
The worker object approach described in Qt 5 QThread's documentation. Give it a signal that you'll connect to your QLineEdit and you should be good to go.