一步步学Qt,第四天-Qt程序发布问题
今天打算给朋友写一个小小的软件,在程序当中加入了一些资源文件,比如图片之类的,可以问题来了.release之后在release目录下面的可执行文件.执行之后确没有加载资源.不解?
有哪位朋友知道的,分享一下!小弟谢过!
下面写一下,在那个程序编写过程中遇到的问题
1. QString到STL string类型的转换
QString t;
QByteArray ba = t.toLatin1();
string str = string(ba.data());
2. 不规则窗体的实现
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void mouseMoveEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *event);
private slots:
void on_pushButton_clicked();
private:
Ui::Widget *ui;
QPoint dragPosition;
};
#endif // WIDGET_H
看看构造函数
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QPixmap pix;
pix.load(":/images/Gmail.png",0,Qt::AvoidDither | Qt::ThresholdAlphaDither | Qt::ThresholdDither);
resize(pix.size());
setMask(pix.mask());
}
鼠标事件响应处理
void Widget::mouseMoveEvent(QMouseEvent *event){
if(event->buttons() & Qt::LeftButton){
move(event->globalPos()- dragPosition);
event->accept();
}
}
void Widget::paintEvent(QPaintEvent *){
QPainter painter(this);
painter.drawPixmap(0,0,QPixmap(":/images/Gmail.png"));
}
void Widget::mousePressEvent(QMouseEvent *event){
if(event->button() == Qt::LeftButton){
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
if(event->button() == Qt::RightButton){
close();
}
}
程序运行效果:
看头文件可知:
Widget继承自QWidget,那么我们把上面的QWidget改成QDialog会如何呢?修改后执行结果有点意外,图片不能正确加载,就是简单的Dialog
或许是的我code有问题,继续研究中.