小弟刚开始学QT 昨天写了个程序但是出现错误,内存不能为读!
.pro文件为
#-------------------------------------------------
#
# Project created by QtCreator 2011-11-19T21:41:17
#
#-------------------------------------------------
TARGET = User_basic_info_modify
TEMPLATE = app
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
头文件为dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui/QDialog>
#include<QLabel>
#include<QLineEdit>
#include<QComboBox>
#include<QTextEdit>
#include<QGridLayout>
#include<QHBoxLayout>
#include<QVBoxLayout>
#include<QTextCodec>
#include<QFrame>
#include<QPixmap>
#include<QPushButton>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
//left
QLabel*UserNameLabel;
QLabel*NameLabel;
QLabel*SexLabel;
QLabel*DepartmentLabel;
QLabel*AgeLabel;
QLabel*OtherLabel;
QLineEdit*UserNameLineEdit;
QLineEdit*NameLineEdit;
QComboBox*SexComboBox;
QTextEdit*DepartmentTextEdit;
QLineEdit*AgeLineEdit;
QGridLayout*LeftLayout;
//right
//top right
QLabel*HeadLabel;
QLabel*HeadIconLabel;
QPushButton*UpdateHeadBtn;
QHBoxLayout*TopRightLayout;
QPixmap* icon;
//bottom right
QLabel*IntroductionLabel;
QTextEdit*IntroductionTextEdit;
QVBoxLayout*RightLayout;
//bottom
QPushButton*OKBtn;
QPushButton*CancelBtn;
QHBoxLayout*ButtomLayout;
};
#endif // DIALOG_H
相关源文件
dialog.cpp
#include "dialog.h"Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("UsrIfor"));
//*****************左侧*************************//
UserNameLabel=new QLabel(tr("用户名:"));
NameLabel=new QLabel(tr("姓名:"));
SexLabel=new QLabel(tr("性别:"));
DepartmentLabel=new QLabel(tr("部门:"));
AgeLabel=new QLabel(tr("年龄:"));
OtherLabel=new QLabel(tr("备注:"));
SexComboBox=new QComboBox;
SexComboBox->addItem("男");
SexComboBox->addItem("女");
UserNameLineEdit=new QLineEdit;
NameLineEdit=new QLineEdit;
AgeLineEdit=new QLineEdit;
DepartmentTextEdit=new QTextEdit();
OtherLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); LeftLayout=new QGridLayout(); //user name
LeftLayout->addWidget(UserNameLabel,0,0);
LeftLayout->addWidget(UserNameLineEdit,0,1);
LeftLayout->addWidget(NameLabel,1,0); //name
LeftLayout->addWidget(NameLineEdit,1,1); LeftLayout->addWidget(SexLabel,2,0); //sex
LeftLayout->addWidget(SexComboBox,2,1);
LeftLayout->addWidget(DepartmentLabel,3,0); //department
LeftLayout->addWidget(DepartmentTextEdit,3,1); LeftLayout->addWidget(AgeLabel,4,0);
LeftLayout->addWidget(AgeLineEdit,4,1); //age
LeftLayout->addWidget(OtherLabel,5,0,1,2); LeftLayout->setColumnStretch(0,1);
LeftLayout->setColumnStretch(1,3);
/*****************右侧************************/
HeadLabel=new QLabel("头像");
QLabel*HeadIconLbale=new QLabel;
QPixmap icon("37.jpg");
HeadIconLabel->setPixmap(icon);
HeadIconLabel->resize(icon.width(),icon.height());
QPushButton*UpdateHeadBtn=new QPushButton("更新");
TopRightLayout=new QHBoxLayout();
TopRightLayout->setSpacing(20);
TopRightLayout->addWidget(HeadLabel);
TopRightLayout->addWidget(HeadIconLabel);
TopRightLayout->addWidget(UpdateHeadBtn);
QLabel*IntroductionLabel=new QLabel("个人说明: ");
IntroductionTextEdit=new QTextEdit; RightLayout=new QVBoxLayout();
RightLayout->setMargin(10);
RightLayout->addLayout(TopRightLayout);
RightLayout->addWidget(IntroductionLabel);
RightLayout->addWidget(IntroductionTextEdit);
/****************bottom**************/
OKBtn=new QPushButton("确定");
CancelBtn=new QPushButton("取消");
ButtomLayout=new QHBoxLayout();
ButtomLayout->addStretch(); ButtomLayout->addWidget(OKBtn);
ButtomLayout->addWidget(CancelBtn);
/***************/
QGridLayout*mainLayout=new QGridLayout(this);
mainLayout->setMargin(15);
mainLayout->setSpacing(10);
mainLayout->addLayout(LeftLayout,0,0);
mainLayout->addLayout(RightLayout,0,1);
mainLayout->addLayout(ButtomLayout,1,0);
//mainLayout->setSizeConstraint(QLayout::setFixedSize);
}
Dialog::~Dialog()
{}
//main.cpp
#include <QtGui/QApplication>
#include "dialog.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
Dialog w;
w.show();
return a.exec();
}