当前位置: 代码迷 >> QT开发 >> 关于保存lineedit的有关问题~
  详细解决方案

关于保存lineedit的有关问题~

热度:42   发布时间:2016-04-25 04:38:17.0
关于保存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();}