QT 之启动画面

程序启动之前有时候需要一段时间来加载, 为了避免用户感觉程序死机卡顿的情况,特别加上开机界面,提醒用户程序正在执行中.

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    
    std::string cur_path("");
    if (!Logging::GetCurrentPath(cur_path))
    {
        std::cout << "Get current path failed!" << std::endl;
    }
    cur_path += std::string(project_name) + std::string("/");

    std::string  img_path += cur_path + std::string("/") + std::string("loginImage.png") ;
    QString str_tmp = QString::fromStdString(img_path);
    QSplashScreen *splash = new QSplashScreen;
    QPixmap pixmap(str_tmp);
    pixmap = pixmap.scaled(400,400,Qt::KeepAspectRatio);
    splash->setPixmap(pixmap);
    splash->setFont((QFont("Helvetica",20)));
    splash->show();
    Qt::Alignment topLeft = Qt::AlignLeft|Qt::AlignTop;
    splash->showMessage("系统启动中,请稍等...",topLeft,Qt::white);
    a.processEvents();

    MainDlg s(cur_path);
    s.show();
    splash->finish(&s);
    delete splash;

    return a.exec();
}

 

你可能感兴趣的:(QT)