还有可能缺少某些头文件
#include<qwidget.h>
#include<qapplication.h>
#include<QGridLayout>
#include<QTextEdit>
#include<QLineEdit>
#include<QLabel>
#include<QMap>
#include<QPushButton>
#include<QVBoxLayout>
#include<QMessageBox>
#include<QString>
class AddressBook : public QWidget
{
// Q_OBJECT
public:
AddressBook();
private:
QLineEdit *nameline;
QTextEdit *addresstext;
QPushButton *addButton;
QPushButton *submitButton;
QPushButton *cancelButton;
};
AddressBook::AddressBook()
{
QLabel *namelabel = new QLabel("name");
QLabel *addresslabel = new QLabel("address");
nameline = new QLineEdit;
addresstext = new QTextEdit;
nameline->setReadOnly(true);
addresstext->setReadOnly(true);
addButton= new QPushButton("&Add");
addButton->show();
submitButton=new QPushButton("&Submit");
submitButton->hide();
cancelButton = new QPushButton("&Cancel");
cancelButton->hide();
QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonLayout->addWidget(addButton);
buttonLayout->addWidget(submitButton);
buttonLayout->addWidget(cancelButton);
buttonLayout->addStretch();
QGridLayout *layout = new QGridLayout;
layout->addWidget(namelabel,0,0);
layout->addWidget(nameline,0,1);
layout->addWidget(addresslabel,1,0,Qt::AlignTop);
layout->addWidget(addresstext,1,1);
layout->addLayout(buttonLayout,1,2);
setLayout(layout);
// QObject::connect(addButton,SIGNAL(clicked()),this,SLOT(addContact()));
// QObject::connect(submitButton,SIGNAL(clicked()),this, SLOT(submitContact()));
// QObject::connect(cancelButton,SIGNAL(clicked()),this, SLOT(cancel()));
}
int main(int argc,char **argv)
{
QApplication app(argc,argv);
AddressBook *add =new AddressBook;
add->show();
return app.exec();
}
还有qobject