• 6823阅读
  • 5回复

[讨论]编写的程序显示内存不能为读,请教高手 ,哪里出问题了 [复制链接]

上一主题 下一主题
离线490642067
 

只看楼主 倒序阅读 楼主  发表于: 2011-11-24
关键词: 求助
小弟刚开始学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();
}

离线jorneyr

只看该作者 1楼 发表于: 2011-11-24
Debug模式运行
离线490642067

只看该作者 2楼 发表于: 2011-11-24
回 1楼(jorneyr) 的帖子
403行的问题
离线490642067

只看该作者 3楼 发表于: 2011-11-24
回 1楼(jorneyr) 的帖子
帮我看看吧
离线490642067

只看该作者 4楼 发表于: 2011-11-24
回 1楼(jorneyr) 的帖子
谢谢啦  这个是底下的调试信息
离线xinqingfly

只看该作者 5楼 发表于: 2011-11-24
你的头文件里定义了个QPixmap* icon;
而在cpp中又定义 QPixmap  icon("37.jpg");
冲突了,改下名字
菜鸟也是鸟
快速回复
限100 字节
 
上一个 下一个