QT实现启动画面

代码如下,详解见注释,效果请自行编译运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QPixmap>
#include <QTextCodec>
#include <QElapsedTimer>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);


    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(codec);


    QSplashScreen splash(QPixmap("./images/logo.png"));
    splash.setDisabled(true); //禁用用户的输入事件响应 否则点击会消失
    splash.show();

    splash.showMessage(QString::fromUtf8("检测版本信息中..."),
                       Qt::AlignCenter|Qt::AlignBottom,Qt::black);


    //实现延时2s
    int delayTime = 2;
    QElapsedTimer timer;
    timer.start();
    while(timer.elapsed() < (delayTime * 1000))
    {
        a.processEvents();
    }

    MainWindow w;
    splash.finish(&w);//关闭启动画面
    w.show();

    return a.exec();
}

BeiTown
2014.09.10

本文链接:QT实现启动画面

转载声明:BeiTown原创,转载请注明来源:BeiTown's Coder 编码之源,谢谢


Tags: , ,

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>