【发布时间】:2012-09-16 06:45:29
【问题描述】:
我正在关注 QtSDK 中列出的 Qt 示例,标题为:“Qt 入门编程”。我的问题是程序没有显示任何对象。
我的 main.cpp 看起来像这样:
#include <QtGui>
#include <notepad.h>
int main(int argv, char **args) {
QApplication app(argv, args);
QVBoxLayout layout;
Notepad notepad();
QWidget window;
window.setLayout(&layout);
window.show();
return app.exec();
}
'notepad.h' 文件:
#ifndef NOTEPAD_H
#define NOTEPAD_H
#include <QtGui>
class Notepad : public QMainWindow {
Q_OBJECT
public:
Notepad();
private slots:
void open();
void save();
void quit();
private:
QTextEdit *text_edit;
QAction *open_action;
QAction *save_action;
QAction *exit_action;
QMenu *file_menu;
};
#endif // NOTEPAD_H
“notepad.cpp”文件:
#include "notepad.h"
Notepad::Notepad() {
open_action = new QAction(tr("&Open"), this);
save_action = new QAction(tr("&Save"), this);
exit_action = new QAction(tr("&Exit"), this);
connect(open_action, SIGNAL(triggered()), this, SLOT(open()));
connect(save_action, SIGNAL(triggered()), this, SLOT(save()));
connect(exit_action, SIGNAL(triggered()), qApp, SLOT(quit()));
file_menu = menuBar()->addMenu(tr("&File"));
file_menu->addAction(open_action);
file_menu->addAction(save_action);
file_menu->addSeparator();
file_menu->addAction(exit_action);
text_edit = new QTextEdit;
setCentralWidget(text_edit);
setWindowTitle(tr("Notepad"));
}
void Notepad::open() {
...
}
void Notepad::save() {
...
}
void Notepad::quit() {
}
我们将不胜感激任何解决问题的帮助。
编辑
我最初的问题问我为什么会因为没有实现“退出”功能而出现编译时错误,以防你想知道:)。
【问题讨论】:
-
为什么notepad.cpp中没有Notepad::quit()方法??!!
-
你忘记写
quit()代码了吗? -
Opps,已修复,现在我的问题似乎是窗口中没有任何内容。
-
请更新您帖子中的问题。
-
@KamranAmini 好的,完成。
标签: c++ qt compilation