C++ c++;qt对话框';OK';主窗口后的按钮设置图像

C++ c++;qt对话框';OK';主窗口后的按钮设置图像,c++,qt,button,C++,Qt,Button,我需要“确定”中的新表单单击“确定”后 From Mainwindow label Set image image path : ./org/org.jpg 艾迪姆·h private slots: void on_buttonBox_accepted(); <---- 'OK' button 专用插槽: 按钮盒上的无效已接受() 您应该创建一个资源文件,在其中导入图片,然后使用以下示例代码: QPixmap pixmap_btn_hw(":/new/myPrefix/btn_har

我需要“确定”中的新表单单击“确定”后

From Mainwindow label Set image
image path : ./org/org.jpg
艾迪姆·h

private slots:
void on_buttonBox_accepted();  <---- 'OK' button
专用插槽:

按钮盒上的无效已接受() 您应该创建一个资源文件,在其中导入图片,然后使用以下示例代码:

QPixmap pixmap_btn_hw(":/new/myPrefix/btn_hardware.png");
QIcon ButtonIcon_hw(pixmap_btn_hw);
ui->hardware_btn->setIcon(ButtonIcon_hw);
ui->hardware_btn->setIconSize(pixmap_btn_hw.rect().size());
ui->hardware_btn->setFocusPolicy(Qt::NoFocus);
要启动外部程序,“sytem()”是个坏主意。以下几点更好:

QProcess *prpr = new QProcess();
prpr->setProcessChannelMode(QProcess::MergedChannels);
prpr->start("raspistill -w 480 -h 360 -q 20 -o aaa.jpg -t 2");
if (!prpr->waitForFinished())
{
   // there was an error
}
else
{
   // command worked!
}

我设法完成了一个最简单的代码:

主窗口

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "dialog.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    //This will change the image in the main window
    void buttonHere();
    //This will change the image in the dialog box
    void buttonDialog();

private:
    Ui::MainWindow *ui;
    Dialog dialog;
    //We need to save the image in QImage so it doesn't disappear
    QImage image;
};

#endif // MAINWINDOW_H
对话.h

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

    //This function changes the image
    void setImage(QString path);

private:
    Ui::Dialog *ui;
    //We need to save the image in QImage so it doesn't disappear
    QImage image;
};

#endif // DIALOG_H
你得到这个结果了吗


在这里尽我最大的努力:您想要一个带有“确定”按钮的警报对话框,单击该按钮时加载一个新表单,在该对话框上有一个来自主窗口中标签文本的图像?addim.cpp QPixmap pix(“./org/org.jpg”);ui2->QWidjet_组织->设置PIXMAP(pix);这个QWidjet_组织是我所理解的,创建一个带有图像的其他形式在这里是最好的,有一个公共功能来改变图像,然后在单击按钮时显示。主窗口中有一张图片,单击“确定”时希望使用标签中的路径更新图像?对于实际问题,使用资源文件有什么区别?另外,如何使用
waitForFinished
系统更好?
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QObject::connect(ui->pushButton_here, SIGNAL(clicked(bool)), SLOT(buttonHere()));
    QObject::connect(ui->pushButton_dialog, SIGNAL(clicked(bool)), SLOT(buttonDialog()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::buttonHere()
{
    //We load the image
    image.load(ui->label->text());
    //We set the label image
    ui->label_2->setPixmap(QPixmap::fromImage(image));
}

void MainWindow::buttonDialog()
{
    //We call the function that changes the dialog image
    dialog.setImage(ui->label->text());
    //We show the dialog
    dialog.show();
}
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

    //This function changes the image
    void setImage(QString path);

private:
    Ui::Dialog *ui;
    //We need to save the image in QImage so it doesn't disappear
    QImage image;
};

#endif // DIALOG_H
#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::setImage(QString path)
{
    //We load the image
    image.load(path);
    //We set the label image
    ui->label->setPixmap(QPixmap::fromImage(image));
}