我想用designer生成界面,现在想点击按钮“ok” 就执行dois函数,现在程序有问题,
谁能帮改一下。
#ifndef DISPLAYER_H
#define DISPLAYER_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QSplitter>
#include <QtGui/QTextEdit>
#include <QtGui/QWidget>
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QWidget *widget;
QWidget *widget1;
QWidget *widget2;
QWidget *widget3;
QSplitter *splitter;
QWidget *widget_2;
QWidget *widget4;
QSplitter *splitter1;
QSplitter *splitter2;
QSplitter *splitter_3;
QLabel *label_2_2_2;
QSplitter *splitter_2;
QLabel *label_3_2_2_2_2_2;
QLabel *label_4_2_2_2_2_2;
QSplitter *splitter3;
QLabel *label_5_2_2;
QLineEdit *lineEdit_4;
QLineEdit *lineEdit_3;
QPushButton *pushButton_2;
QPushButton *pushButton;
QLineEdit *lineEdit;
QLineEdit *lineEdit_2;
QTextEdit *textEdit;
QLabel *label;
void setupUi(QMainWindow *MainWindow)
{
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(QSize(185, 239).expandedTo(MainWindow->minimumSizeHint()));
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
widget = new QWidget(centralWidget);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(80, 10, 90, 221));
widget1 = new QWidget(centralWidget);
widget1->setObjectName(QString::fromUtf8("widget1"));
widget1->setGeometry(QRect(81, 11, 90, 191));
widget2 = new QWidget(centralWidget);
widget2->setObjectName(QString::fromUtf8("widget2"));
widget2->setGeometry(QRect(82, 12, 90, 136));
widget3 = new QWidget(centralWidget);
widget3->setObjectName(QString::fromUtf8("widget3"));
widget3->setGeometry(QRect(9, 13, 61, 175));
splitter = new QSplitter(centralWidget);
splitter->setObjectName(QString::fromUtf8("splitter"));
splitter->setGeometry(QRect(10, 14, 133, 21));
splitter->setOrientation(Qt::Horizontal);
widget_2 = new QWidget(centralWidget);
widget_2->setObjectName(QString::fromUtf8("widget_2"));
widget_2->setGeometry(QRect(87, 294, 31, 16));
widget4 = new QWidget(centralWidget);
widget4->setObjectName(QString::fromUtf8("widget4"));
widget4->setGeometry(QRect(10, 60, 88, 46));
splitter1 = new QSplitter(centralWidget);
splitter1->setObjectName(QString::fromUtf8("splitter1"));
splitter1->setGeometry(QRect(10, 100, 120, 21));
splitter1->setOrientation(Qt::Horizontal);
splitter2 = new QSplitter(centralWidget);
splitter2->setObjectName(QString::fromUtf8("splitter2"));
splitter2->setGeometry(QRect(10, 140, 137, 21));
splitter2->setOrientation(Qt::Horizontal);
splitter_3 = new QSplitter(centralWidget);
splitter_3->setObjectName(QString::fromUtf8("splitter_3"));
splitter_3->setGeometry(QRect(10, 50, 111, 21));
splitter_3->setOrientation(Qt::Horizontal);
label_2_2_2 = new QLabel(centralWidget);
label_2_2_2->setObjectName(QString::fromUtf8("label_2_2_2"));
label_2_2_2->setGeometry(QRect(10, 40, 27, 21));
splitter_2 = new QSplitter(centralWidget);
splitter_2->setObjectName(QString::fromUtf8("splitter_2"));
splitter_2->setGeometry(QRect(10, 90, 120, 21));
splitter_2->setOrientation(Qt::Horizontal);
label_3_2_2_2_2_2 = new QLabel(centralWidget);
label_3_2_2_2_2_2->setObjectName(QString::fromUtf8("label_3_2_2_2_2_2"));
label_3_2_2_2_2_2->setGeometry(QRect(10, 70, 29, 21));
label_4_2_2_2_2_2 = new QLabel(centralWidget);
label_4_2_2_2_2_2->setObjectName(QString::fromUtf8("label_4_2_2_2_2_2"));
label_4_2_2_2_2_2->setGeometry(QRect(10, 100, 46, 21));
splitter3 = new QSplitter(centralWidget);
splitter3->setObjectName(QString::fromUtf8("splitter3"));
splitter3->setGeometry(QRect(11, 132, 91, 17));
splitter3->setOrientation(Qt::Horizontal);
label_5_2_2 = new QLabel(splitter3);
label_5_2_2->setObjectName(QString::fromUtf8("label_5_2_2"));
lineEdit_4 = new QLineEdit(centralWidget);
lineEdit_4->setObjectName(QString::fromUtf8("lineEdit_4"));
lineEdit_4->setGeometry(QRect(67, 100, 111, 21));
lineEdit_3 = new QLineEdit(centralWidget);
lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
lineEdit_3->setGeometry(QRect(67, 70, 111, 21));
pushButton_2 = new QPushButton(centralWidget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(100, 210, 75, 23));
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(10, 210, 75, 23));
lineEdit = new QLineEdit(centralWidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(67, 14, 111, 21));
lineEdit_2 = new QLineEdit(centralWidget);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
lineEdit_2->setGeometry(QRect(67, 40, 111, 21));
textEdit = new QTextEdit(centralWidget);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setGeometry(QRect(10, 154, 168, 53));
label = new QLabel(centralWidget);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 14, 52, 21));
label->setTextFormat(Qt::AutoText);
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "E_BOOK"));
label_2_2_2->setText(QApplication::translate("MainWindow", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">Sex</span></p></body></html>"));
label_3_2_2_2_2_2->setText(QApplication::translate("MainWindow", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; color:#000000;\">Age</span></p></body></html>"));
label_4_2_2_2_2_2->setText(QApplication::translate("MainWindow", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; color:#000000;\">Phone</span></p></body></html>"));
label_5_2_2->setText(QApplication::translate("MainWindow", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; color:#000000;\">Address</span></p></body></html>"));
pushButton_2->setText(QApplication::translate("MainWindow", "CANCE"));
pushButton->setText(QApplication::translate("MainWindow", "OK"));
label->setText(QApplication::translate("MainWindow", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">Name</span></p></body></html>"));
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {
Q_OBJECT
public:
MainWindow();
public slots:
void dois();
};
} // namespace Ui
#endif // DISPLAYER_H
/////////////////////////////////////////////////////////////////////////
#include "displayer.h"
#include <QFile>
using namespace Ui;
MainWindow::MainWindow(){
connect(pushButton,SIGNAL(clicked()),this,SLOT(dois()));
}
MainWindow::dois()
{ char line[] = " hello world ,this is a Qt";
QFile qfile("gyh.txt");
if(qfile.open(IO_Append))
{
for(int i= 0;i<strlen(line1);i++)
qfile.putch(line1[i]);
}
qfile.close();
}
}
///////////////////////////////////////////////////////////////////////////
#include <QApplication>
#include "displayer.h"
using namespace Ui;
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QMainWindow mainwindow;
MainWindow ui;
ui.setupUi(&mainwindow);
mainwindow.show();
return app.exec();
}
[ 此贴被XChinux在2005-09-09 16:00重新编辑 ]