gpt4 book ai didi

c++ - 执行自定义qdialog

转载 作者:行者123 更新时间:2023-12-01 19:25:25 25 4
gpt4 key购买 nike

我在尝试运行此应用程序时遇到错误...错误消息是:

main.cpp(11): 错误:表达式必须具有类类型 int r = 对话框.exec();我不知道为什么!!!

我正在使用 qmake 生成 make 文件...我已将必要的文件添加到 *.pro 文件中,因为 Dialog 是从 QDialog 继承的,我应该有权访问函数 exec!

#include <QtGui>
#include <QDialog>
#include <QtUtil.h>
#include <Mathematics.h>
#include <Pair.h>
#include "View.h"

class QMesseageBox;
class QAction;
class QDialogButtonBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QTextEdit;

class Dialog : public QDialog {
Q_OBJECT
public:
Dialog() {
QHBoxLayout *layout = new QHBoxLayout;
// prevent left vertical box from growing when main window resized
layout->addStretch(1);

QLabel* lab_Layers = new QLabel(tr("Layers"));
d_inline = new QLineEdit;
d_inline->setText("50");

scene = new QGraphicsScene(0, 0, 500, 500);
view = new View;

layout->addWidget(view);
view->setScene(scene);

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(layout);
setLayout(mainLayout);
setWindowTitle(tr("VI Smooth 0.4"));
}

private slots:
// scroll the "after" window when "before" one is scrolled (so they
// remain in sync)

private:
QAction* exitAction;
QtUtil qt;
QLineEdit* d_inline;
QGraphicsScene* scene;
QGraphicsView* view;
};

主类

#include <QApplication>
#include <QMessageBox>
#include "Dialog.h"

int
main(int argc, char **argv) {
QApplication app(argc, argv);
argv++;
Dialog dialog();
// dialog.showMaximized();
int r = dialog.exec();
return 0;
}

最佳答案

它应该看起来像这样。如果创建Dialog对象,则需要调用show()。并且您还需要在 main() 中返回 app.exec()

#include <QApplication>
#include <QMessageBox>
#include "Dialog.h"

int
main(int argc, char **argv) {
QApplication app(argc, argv);
argv++;
Dialog dialog;
dialog.show()
return app.exec(argc, argv);
}

关于c++ - 执行自定义qdialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8686971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com