查看完整版本: [--
splash类在Linux和Windows系统下有不同表现
--]
QTCN开发网
->
Qt基础编程
->
splash类在Linux和Windows系统下有不同表现
[打印本页]
登录
->
注册
->
回复主题
->
发表主题
pheigenbaum
2017-08-10 16:33
splash类在Linux和Windows系统下有不同表现
我建立了一个简单的工程,就是用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下的正常表现:
[attachment=17631] [attachment=17632]
在Ubuntu上的表现是这样的:
[attachment=17633]
只看到那个框,在第二次show message之后,显示出图片,和windows系统下的最终图片一样
论坛里的高手们能否指教?
pheigenbaum
2017-08-11 08:30
眼看就要沉了,还是自己顶起来
没有高手来看吗?
yuyu414
2017-08-11 08:45
如果一定要这么写的话可以在showmessage后面加一句qApp->processEvents();
pheigenbaum
2017-08-11 14:08
yuyu414
:
如果一定要这么写的话可以在showmessage后面加一句qApp->processEvents();
(2017-08-11 08:45)
尝试过了,不管是加在main函数里,还是加在构造函数里,都一样
dosmlp
2017-08-15 13:08
可以换图片格式试一下
pheigenbaum
2017-08-22 16:30
把图片换成BMP格式也一样
查看完整版本: [--
splash类在Linux和Windows系统下有不同表现
--] [--
top
--]
Powered by
phpwind
v8.7
Code ©2003-2011
phpwind
Gzip disabled