首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

关于保存lineedit的有关问题~

2012-07-29 
关于保存lineedit的问题~~大神快救救我啊,马上快被搞崩溃了~~先上代码吧~~C/C++ code//dialog.h如下:#ifnd

关于保存lineedit的问题~~
大神快救救我啊,马上快被搞崩溃了~~

先上代码吧~~

C/C++ code
//dialog.h如下:#ifndef DIALOG_H#define DIALOG_H#include <QWizard>#include <QPainter>#include <QtGui/QWidget>#include <QFile>#include <QTextStream>class QCheckBox;class QGroupBox;class QLabel;class QLineEdit;class QRadioButton;////////////////////////////////////////////////////////////////////////class ClassWizard : public QWizard{    Q_OBJECTpublic:    ClassWizard(QWidget *parent = 0);    //void accept();};class ClassConfigPage : public QWizardPage{    Q_OBJECTpublic:    ClassConfigPage(QWidget *parent = 0);private:    QLineEdit *lineEdit31;    QLineEdit *lineEdit32;    QLineEdit *lineEdit33;    QLineEdit *lineEdit34;    QLineEdit *lineEdit35;    QLabel *labelconfig;    QLabel *label31;    QLabel *label32;    QLabel *label33;    QLabel *label34;    QLabel *label35;    QPushButton *OKButton;private slots://    void savedata();      void on_OKButton_clicked();};//dialog.cpp如下#include "dialog.h"#include "ui_dialog.h"#include <QtGui>#include <QTextStream>ClassWizard::ClassWizard(QWidget *parent)    : QWizard(parent){    //addPage(new IntroPage);    //addPage(new ClassInfoPage);    addPage(new ClassConfigPage);    //addPage(new ClassConfigShowPage);    //addPage(new ClassThroughputPage);    //setPixmap(QWizard::BannerPixmap, QPixmap(":/images/banner.jpg"));   // setPixmap(QWizard::BackgroundPixmap, QPixmap(":/images/background.jpg"));    setWindowTitle(tr("Class Wizard"));}ClassConfigPage::ClassConfigPage(QWidget *parent)    : QWizardPage(parent){    setTitle(tr("ConfigPage"));   // setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/background.jpg"));    labelconfig = new QLabel("ConfigPage");    labelconfig->setWordWrap(true);    label31 = new QLabel("UE Style(central;middle;edge):");    QLineEdit *lineEdit31 = new QLineEdit;    label31->setBuddy(lineEdit31);    QHBoxLayout *layout31 = new QHBoxLayout;    layout31->addWidget(label31);    layout31->addWidget(lineEdit31);    label32 = new QLabel("Number of BS:");    QLineEdit *lineEdit32 = new QLineEdit;    label32->setBuddy(lineEdit32);    QHBoxLayout *layout32 = new QHBoxLayout;    layout32->addWidget(label32);    layout32->addWidget(lineEdit32);    label33 = new QLabel("Number of UE:");    QLineEdit *lineEdit33 = new QLineEdit;    label33->setBuddy(lineEdit33);    QHBoxLayout *layout33 = new QHBoxLayout;    layout33->addWidget(label33);    layout33->addWidget(lineEdit33);    label34 = new QLabel("...:");    QLineEdit *lineEdit34 = new QLineEdit;    label34->setBuddy(lineEdit34);    QHBoxLayout *layout34 = new QHBoxLayout;    layout34->addWidget(label34);    layout34->addWidget(lineEdit34);    label35 = new QLabel("...:");    QLineEdit *lineEdit35 = new QLineEdit;    label35->setBuddy(lineEdit35);    QHBoxLayout *layout35 = new QHBoxLayout;    layout35->addWidget(label35);    layout35->addWidget(lineEdit35);/////////////////////////////////////////////////////////////////    QPushButton *OKButton = new QPushButton("OK");    QVBoxLayout *leftlayout = new QVBoxLayout;    leftlayout->addLayout(layout31);    leftlayout->addLayout(layout32);    leftlayout->addLayout(layout33);    leftlayout->addLayout(layout34);    leftlayout->addLayout(layout35);    QHBoxLayout *downlayout = new QHBoxLayout;    downlayout->addLayout(leftlayout);    downlayout->addWidget(OKButton);    QVBoxLayout *layout3 = new QVBoxLayout;    layout3->addWidget(labelconfig);    layout3->addLayout(downlayout);    setLayout(layout3);   QObject::connect(OKButton, SIGNAL(clicked()), this, SLOT(on_OKButton_clicked()));}void ClassConfigPage::on_OKButton_clicked(){    QFile file("1234.txt");    file.open(QIODevice::ReadWrite|QIODevice::Text);    QTextStream in1(&file);    //in1 << "sdkfjioweu" <<endl;    in1 << lineEdit31->text() << endl;                    /////问题在这~~    QTextStream in2(&file);    in2 << lineEdit32->text() << endl;    QTextStream in3(&file);    in3 << lineEdit33->text() << endl;    QTextStream in4(&file);    in4 << lineEdit34->text() << endl;    QTextStream in5(&file);    in5 << lineEdit35->text() << endl;}//main.cpp如下:#include <QApplication>#include <QTranslator>#include <QLocale>#include <QLibraryInfo>#include "dialog.h"int main(int argc, char *argv[]){    //Q_INIT_RESOURCE(ClassWizard);    QApplication app(argc, argv);    QString translatorFileName = QLatin1String("qt_");    translatorFileName += QLocale::system().name();    QTranslator *translator = new QTranslator(&app);    if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))        app.installTranslator(translator);    ClassWizard wizard;    wizard.show();//    Widget w;//    w.show();    return app.exec();} 



先说下我想要实现的效果:页面上有几个lineedit,一个button,点击按钮后将lineedit中的内容保存到txt文档里;

我写了几个页面,这是其中的一个,问题出在保存lineedit那里;现在这样程序能跑通,但是点击按钮之后会提示:class Wizard:test_next3.exe 应用程序错误;“0x00d90f16”指令引用的“0x000000004”内存。该内存不能为“read”。

这是什么原因呢,如果不保存lineedit,只保存//in1 << "sdkfjioweu" <<endl;这个,就完全没问题;

ps:貌似槽函数中的lineedit和类里的lineedit不是一个,但又不能在类外定义,那样跑不通

大神救救我啊~~

[解决办法]
每个QLineEdit被声明了两遍,把构造函数内的QLineEdit声明去掉。

热点排行