关于QT中使用pixmap进行图片的切换问题
时间:10-02
整理:3721RD
点击:
由于做项目刚刚接触QT,对槽机制不是很了解~求指教~~下面是一小段代码~代码执行后一按下change程序就崩溃
- PictureChange::PictureChange(QWidget *parent) : QDialog(parent)
- {
- picName="/home/common/my_program/picture/picture.jpg";
- QLabel *label=new QLabel;
- button_change=new QPushButton("change"); connect(button_change,SIGNAL(clicked()),this,SLOT(change_clicked()));
- pixmap=new QPixmap;
- pixmap->load(picName);
- label->setPixmap(*pixmap);
- 布局~
- }
- void PictureChange::change_clicked()
- {
- QString picpath1,picpath2;
- picpath1="/home/common/my_program/picture/picture.jpg"; picpath2="/home/common/my_program/picture/picture2.jpg";
- pixmap->load(picpath2);
- label->setPixmap(*pixmap);//执行此句后出问题,不知应如何实现图片切换
- }
- #ifndef PICTURECHANGE_H
- #define PICTURECHANGE_H
- #include <QDialog>
- class QPushButton;
- class QLabel;
- class PictureChange:public QDialog {
- Q_OBJECT
- public: PictureChange(QWidget *parent=0);
- private slots: void change_clicked();
- private:
- QString picName;
- QLabel *label;
- QPixmap *pixmap;
- QPushButton *button_change;
- QPushButton *button_quit; };
- #endif