QApplication object construction time is too long



  • I want to use the QSplashScreen. But i find QApplication a(argc,argv) or QtSingleApplication a(argc,argv) command take up too much time.

    First: I create new Qt Gui application to test the time. It was very good. just spend 1s;

    #include "mainwindow.h"
    #include <QApplication>
    #include <QSplashScreen>
    #include <QThread>
    #include <QTime>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        qDebug() << "0--" << QTime::currentTime();///< 0-- QTime("18:11:00.998")
        QApplication a(argc, argv);
        qDebug() << "1--" << QTime::currentTime();///< 1-- QTime("18:11:01.192")
    
        QPixmap pixmap(":/png/time.jpg");
        QSplashScreen splash(pixmap);
        splash.show();
    
        a.processEvents();
    
        MainWindow w;
    
        QThread::sleep(5);
    
        w.show();
    
        splash.finish(&w);
        return a.exec();
    }
    

    Second: I test the time in my qt project now. using the QApplication it was spent 12s;

    #include "mainwindow.h"
    #include <QApplication>
    #include <QTime>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        qDebug() << "0--" << QTime::currentTime(); ///< 0-- QTime("18:20:28.031")
        QApplication a(argc,argv);
        qDebug() << "1--" << QTime::currentTime(); ///< 1-- QTime("18:20:40.122")
    
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    
    

    Last: Because i used the QtSingleApplication. I doubt it. But, using the time is same with QApplication both about 12s.

    #include "module_singleApp/qtsingleapplication.h"
    #include "mainwindow.h"
    #include <QTime>
    #include <QDebug>
    
    #ifndef JOE
    int main(int argc, char *argv[])
    {
        qDebug() << "0--" << QTime::currentTime(); ///< 0-- QTime("18:24:19.141")
        QtSingleApplication a(argc, argv);
        qDebug() << "1--" << QTime::currentTime(); ///< 1-- QTime("18:24:31.316")
    
        if(a.sendMessage("Wake up!")){
            return 0;   ///<Not allow to use the goto
        }
    
        MainWindow w;
        a.setActivationWindow(&w);
    
        w.show();
    
        return a.exec();
    }
    

    I guest the reason maybe is the load some dll and lib files in my pro file.

    I just want to use the QSplashScreen in my main.cpp file. But, QApplication construct takes up too much time.

    I also test with release. also takes up too much time.

    -_-!...



  • Both QGuiAppliaction and QApplication example are using a QApplication. Are you sure about those example ?

    QSingleApplication doesn't seem to be part of the official Qt distribution. It might use deprecated functions. In my opinion, do not use it.

    Do you pass any argument to your program ?

    What is your system context ?


  • Lifetime Qt Champion

    Hi,

    @eti_nne QtSingleApplication is part of the QtSolutions module. Even if a bit old it's still used in e.g. Qt Creator.

    @joeQ What version of Qt are you talking about ? On what OS ? What's the load of your system ?



  • @eti_nne

    Why i used the QtSingleApplication in my project, because i want QtSingleApplication component provides for applications that can be only started once by user.

    But, i found QtSingleApplication construct take up too much time.



  • @SGaist

    Qt version 5.7.0
    Window

    In my pro file. i has some lib and dll files to link or load.



  • @SGaist

    I want to use the QSplashScreen provides a splash screen that can be shown during application startup. but, i found QtSingleApplication a(argc,argv) command takes up too much time.

    If i use QSplashScreen, must be after QtSingleApplication.

    How to save it?


  • Lifetime Qt Champion

    Window is a bit vague, it can range from XP to 10.

    What dependencies do you have ?



  • @SGaist

    what your mean maybe it was the system problem? Wait a moment, i try again. project in the company. i am at home now. ok, i will try the QtSingleApplication in my win10. Wait a moment.



  • @SGaist

    I download the QtSingleapplication source code test again in my win10. it takes up time less than 1s. very fast.

    probably because of a systeam problem or others.

    Ok, The problem pause.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.