当前位置: 代码迷 >> QT开发 >> 关于this指针的使用异常有关问题~大神帮忙啊
  详细解决方案

关于this指针的使用异常有关问题~大神帮忙啊

热度:94   发布时间:2016-04-25 04:38:52.0
关于this指针的使用错误问题~大神帮忙啊~~
先把代码贴上吧

C/C++ code
QWizardPage *createPage2(){    QWizardPage *page2 = new QWizardPage;    page2->setTitle("page2");    QLabel *label2 = new QLabel("page2"                           ".");    label2->setWordWrap(true);///////////////////////////////////////////////////////////////    QLabel *label21;    QLineEdit *lineEdit21;    label21 = new QLabel("UE Style(central;middle;edge):");    lineEdit21 = new QLineEdit;    label21->setBuddy(lineEdit21);    QHBoxLayout *layout21 = new QHBoxLayout;    layout21->addWidget(label21);    layout21->addWidget(lineEdit21);    QLabel *label22;    QLineEdit *lineEdit22;    label22 = new QLabel("Number of BS:");    lineEdit22 = new QLineEdit;    label22->setBuddy(lineEdit22);    QHBoxLayout *layout22 = new QHBoxLayout;    layout22->addWidget(label22);    layout22->addWidget(lineEdit22);    QLabel *label23;    QLineEdit *lineEdit23;    label23 = new QLabel("Number of UE:");    lineEdit23 = new QLineEdit;    label23->setBuddy(lineEdit23);    QHBoxLayout *layout23 = new QHBoxLayout;    layout23->addWidget(label23);    layout23->addWidget(lineEdit23);    QLabel *label24;    QLineEdit *lineEdit24;    label24 = new QLabel("...:");    lineEdit24 = new QLineEdit;    label24->setBuddy(lineEdit24);    QHBoxLayout *layout24 = new QHBoxLayout;    layout24->addWidget(label24);    layout24->addWidget(lineEdit24);    QLabel *label25;    QLineEdit *lineEdit25;    label25 = new QLabel("...:");    lineEdit25 = new QLineEdit;    label25->setBuddy(lineEdit25);    QHBoxLayout *layout25 = new QHBoxLayout;    layout25->addWidget(label25);    layout25->addWidget(lineEdit25);/////////////////////////////////////////////////////////////////    QPushButton *OKButton = new QPushButton("OK");    QVBoxLayout *leftlayout = new QVBoxLayout;    leftlayout->addLayout(layout21);    leftlayout->addLayout(layout22);    leftlayout->addLayout(layout23);    leftlayout->addLayout(layout24);    leftlayout->addLayout(layout25);    QHBoxLayout *downlayout = new QHBoxLayout;    downlayout->addLayout(leftlayout);    downlayout->addWidget(OKButton);    QVBoxLayout *layout2 = new QVBoxLayout;    layout2->addWidget(label2);    layout2->addLayout(downlayout);    page2->setLayout(layout2);    QObject::connect(OKButton, SIGNAL(clicked()), this, SLOT(save()));   //////////错误在这~~    return page2;}void save(){    QFile file("F:/QtWorkshop/test_next/123.txt");    file.open(QIODevice::ReadWrite|QIODevice::Text);    QTextStream in1(&file);    in1 << lineEdit21->text() << endl;                                  //////错误    QTextStream in2(&file);    in2 << lineEdit22->text() << endl;                                    //////错误    QTextStream in3(&file);    in3 << lineEdit23->text() << endl;                                   //////错误    QTextStream in4(&file);    in4 << lineEdit24->text() << endl;                                  //////错误    QTextStream in5(&file);    in5 << lineEdit25->text() << endl;                                  //////错误}



错误提示是:
1、invalid of use of 'this' in non-member function
2、'lineEdit21' was not declared in this scope

这是怎么回事啊,我知道this指针肯定用的不对,但那个信号槽里面应该如何写啊??
还有为什么会提示lineEdit21没有声明啊~?

我想完成的功能是:在页面2上添加几个lineEdit,然后点击OK按钮会把lineEdit中的内容保存到txt文档里,不知道我的save()函数写在那有没有问题啊??

我把主函数也贴在下面吧,方便跑通

C/C++ code
#include <QtGui/QApplication>#include "dialog.h"#include <qwizard.h>#include <QLabel>#include <QtGui>int main(int argc, char *argv[]){    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);    QWizard wizard;//    wizard.addPage(createIntroPage());//    wizard.addPage(createPage1());    wizard.addPage(createPage2());//    wizard.addPage(createPage3());//    wizard.addPage(createPage4());    wizard.setWindowTitle("Trivial Wizard");    wizard.show();    return app.exec();}
  相关解决方案