我建立了一个简单的工程,就是用QSplashScreen类来做程序启动过程。
该类是在mainwindow.cpp里使用的,先new 一个splash出来,直接show,再
显示一个message,
然后等待一定时间,再显示另一个message,再等待一定时间,就 finish 掉。
该工程在
Windows下的 QT5.5 里表现和预想中一样,在show的时候显示出
图片来,在show message时看到文字,
在finish之后关闭。
但是在
Linux(Ubuntu16.04)下的QT5.5 里,却不一样:在show之后显示出一个和图片大小相同的外框,却
没有图片,
直到最后一次show message后才显示出图片来,在finish之后关闭。
我尝试过在main函数里加入 app.processEvents(),无效,把splash移到main函数里实现,也无效,不知道是什么原因。
注:本人是QT小白,
新手入门才10天。
下面是原程序
文件:
//
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QSplashScreen>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
QSplashScreen *splash;
};
#endif // WIDGET_H
// widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QtTest>
#include <QTextEdit>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
splash = new QSplashScreen(tr(":/splash/timg.jpg"));
splash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(QObject::tr("Setting up the main
Window..."), topRight, Qt::red);
QTest::qSleep(1000);
splash->showMessage(tr("Loading modules..."), topRight, Qt::blue);
QTest::qSleep(2000);
splash->finish(this);
}
Widget::~Widget()
{
delete ui;
}
// main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
在windows下的正常表现:
在Ubuntu上的表现是这样的:
只看到那个框,在第二次show message之后,显示出图片,和windows系统下的最终图片一样
论坛里的高手们能否指教?