当前位置:编程学习 > wap >>

FindBtn->setEnabled(!text.isEmpty()); 这里编译出错: 'text' was not declared in this

mainwindow.h

#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include<QDialog>

class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;

class FindDialog:public QDialog
{
    Q_OBJECT
public:
    FindDialog(QWidget *parent=0);
signals:
    void findNext(const QString $str,Qt::CaseSensitivity cs);
    void findPrevious(const QString $str,Qt::CaseSensitivity cs);
private slots:
    void findClicked();
    void enableFindButton(const QString $text);
private:
    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;
};

#endif


mainwindow.cpp

#include<QtGui>
#include<mainwindow.h>
FindDialog::FindDialog(QWidget *parent)
    :QDialog(parent)
{
    label=new QLabel(tr("Find &what:"));
    lineEdit=new QLineEdit;
    label->setBuddy(lineEdit);

    caseCheckBox=new QCheckBox(tr("Match$case"));
    backwardCheckBox=new QCheckBox(tr("Search$backward"));

    findButton=new QPushButton(tr("$Find"));
    findButton->setDefault(true);
    findButton->setEnabled(false);

    closeButton=new QPushButton(tr("close"));

    connect(lineEdit,SIGNAL(textChanged(const QString $)),
            this,SLOT(enableFindButton(const QString $)));
    connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
    connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));

    QHBoxLayout *topleftlayout=new QHBoxLayout;
    topleftlayout->addWidget(label);
    topleftlayout->addWidget(lineEdit);

    QVBoxLayout *leftlayout=new QVBoxLayout;
    leftlayout->addLayout(topleftlayout);
    leftlayout->addWidget(caseCheckBox);
    leftlayout->addWidget(backwardCheckBox);

    QVBoxLayout *rightLayout=new QVBoxLayout;
    rightLayout->addWidget(findButton);
    rightLayout->addWidget(closeButton);
    rightLayout->addStretch();

    QHBoxLayout *mainLayout=new QHBoxLayout;
    mainLayout->addLayout(leftlayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);

    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
}


void FindDialog::findClicked()
{
    QString text=lineEdit->text();
    Qt::CaseSensitivity cs=caseCheckBox->isChecked()?Qt::CaseSensitive:Qt::CaseInsensitive;
    if(backwardCheckBox->isChecked())
           {emit findPrevious(text,cs);}
    else   {emit findNext(text,cs);}
}
void FindDialog::enableFindButton(const QString $text)
{

    findButton->setEnabled(!text.isEmpty());
}

#include<QApplication>
#include "mainwindow.h"
int main(int argc,char **argv)
{
    QApplication app(argc,argv);
    FindDialog *dialog=new FindDialog;
    dialog->show();
    return app.exec();
}








--------------------编程问答-------------------- FindBtn->setEnabled(!text.isEmpty());
代码里没有上面这行! --------------------编程问答--------------------

void FindDialog::enableFindButton(const QString $text)
{

    findButton->setEnabled(!text.isEmpty());
}

$确定不是&,另外你的代码里面,很多地方都用的$而不是&,什么情况?楼主学过C++?
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,