/********************************************************************************
** Form generated from reading UI file 'mywindow.ui'
**
** Created: Thu Nov 10 10:28:46 2011
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MYWINDOW_H
#define UI_MYWINDOW_H
#include
#include
#include
#include
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
class Ui_MyWindow
{
public:
QWidget *MyScreen;
QPushButton *MyButton;
void setupUi(QMainWindow *MyWindow)
{
if (MyWindow->objectName().isEmpty())
MyWindow->setObjectName(QString::fromUtf8("MyWindow"));
MyWindow->resize(100, 100);
MyScreen = new QWidget(MyWindow);
MyScreen->setObjectName(QString::fromUtf8("MyScreen"));
MyButton = new QPushButton(MyScreen);
MyButton->setObjectName(QString::fromUtf8("MyButton"));
MyButton->setGeometry(QRect(25, 25, 50, 50));
MyWindow->setCentralWidget(MyScreen);
retranslateUi(MyWindow);
QMetaObject::connectSlotsByName(MyWindow);
} // setupUi
void retranslateUi(QMainWindow *MyWindow)
{
MyWindow->setWindowTitle(QApplication::translate("MyWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
MyButton->setText(QApplication::translate("MyWindow", "PushButton", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MyWindow: public Ui_MyWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MYWINDOW_H
最后编译运行,点击按钮就可以看到打印信息了。
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
namespace Ui {
class MyWindow;
}
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MyWindow(QWidget *parent = 0);
~MyWindow();
private:
Ui::MyWindow *ui;
public slots:
void ButtonClickedMsg(void);
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mywindow.h"
MyWindow::MyWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MyWindow)
{
ui->setupUi(this);
connect(ui->MyButton, SIGNAL(clicked()), this, SLOT(ButtonClickedMsg()));
}
MyWindow::~MyWindow()
{
delete ui;
}
void MyWindow::ButtonClickedMsg(void)
{
qDebug("You just clicked the Button \"A\"\n");
}
#include
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWindow w;
w.show();
return a.exec();
}