【发布时间】:2013-12-06 20:59:53
【问题描述】:
您好,我是 C++ 新手,我正试图理解这些概念。 我正在创建一个非常简单的应用程序以在教程的帮助下开始,所以我尝试自己做第一次尝试。 除了 main.cpp 之外,我遇到了 file.h 和 file.cpp 的问题 我想单击按钮框中的按钮“确定”并在文本框中显示文本。 这里首先是 MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_MainWindow.h"
class MainWindow: public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow(QMainWindow *parent = 0);
private slots:
//here is where im tyring to add a slot.
void on_buttonbox_buttonClicked ( QAbstractButton * );
// void on_inputSpinBox2_valueChanged(int value);
private:
Ui::MainWindow ui;
};
#endif
接下来是 MainWindow.cpp
#include <QtGui>
#include "MainWindow.h"
MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
//This is where i would like to catch the clicked signal from the ok button and add the text to the text box.
void MainWindow::on_buttonbox_buttonClicked ( QAbstractButton * ){
ui.textEdit->setText(QString::number(16));
}
我试图尽可能简单地让它运行,它会编译但我无法让信号和插槽说话,我哪里出错了......记住全新的。
【问题讨论】:
-
我不知道该放在哪里
-
将
connect(...)放入构造函数的实现(!)中(在您的cpp 文件中,在ui.setupUi(this);行之后)。一会儿我会把它编辑成我的答案......