0

I having trouble with this code, since the QApplication line takes several seconds to return:

#include <QTime>
#include <QApplication>

#include <chrono>
#include <iostream>

int main(int argc, char **argv) {
  auto t1 = std::chrono::high_resolution_clock::now();
  QApplication app(argc, argv);
  auto t2 = std::chrono::high_resolution_clock::now();
  std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() << " ms" << std::endl;
  return 0;
}

With MinGW, the program returns 4702 ms or something like that everytime (except a crazy 159983 ms once!). With Visual Studio, I waited 12 s the first time, then 0.6 s the other times, which is acceptable.

I am compiling with Ninja or CMake. What could be the reason of the QApplication being so slow to be created and how to speed that up? Thank you very much for your help.

EDIT: removing all the unnecessary dll in my directory (opencv_xxx.dll, etc.) solves the problem. But why? And how to avoid this?


My env: Windows 10, gcc 10.3.0, qt-5.15.1/mingw81_64

My compilation output with ninja:

cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe -O2 -g -DNDEBUG  -Wl,-rpath,. programs/CMakeFiles/meyeEval.dir/meyeEval.cpp.obj  -o bin\meyeEval.exe -Wl,--out-implib,lib\libmeyeEval.dll.a -Wl,--major-image-version,0,--minor-image-version,0  D:/Dev/dependances/T5/x64/qt-5.15.1/5.15.1/mingw81_64/lib/libQt5Qml.a D:/Dev/dependances/T5/x64/qt-5.15.1/5.15.1/mingw81_64/lib/libQt5Widgets.a D:/Dev/dependances/T5/x64/qt-5.15.1/5.15.1/mingw81_64/lib/libQt5Network.a D:/Dev/dependances/T5/x64/qt-5.15.1/5.15.1/mingw81_64/lib/libQt5Gui.a D:/Dev/dependances/T5/x64/qt-5.15.1/5.15.1/mingw81_64/lib/libQt5Core.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd .
PJ127
  • 986
  • 13
  • 23
  • 1
    I'm not sure it it is safe to use `QTimer` before `QApplication` is initialized. Use `std::chrono` to take this measurement. – Marek R Dec 17 '21 at 09:33
  • 1
    `removing all the unnecessary dll in my directory (opencv_xxx.dll, etc.) solves the problem. But why?` Qt uses plugins a lot, so probably those dll-s are scanned for additional functionalities. – Marek R Dec 17 '21 at 09:35
  • 1
    did you test timing in `debug` mode? you should test it in `release` mode. – Parisa.H.R Dec 17 '21 at 14:44
  • Thank you. I tested in `Release` and `RelWithDebInfo`, with no change. – PJ127 Dec 17 '21 at 15:05

0 Answers0