Ajuda Qt::CaseSensitive



  • @#ifndef FINDTEST_H
    #define FINDTEST_H
    #include<QCheckBox>
    #include<QLabel>
    #include<QLineEdit>
    #include<QPushButton>
    #include<QString>
    #include<qnamespace.h>
    #include<Qt>

    #include <QDialog>
    class QCheckBox;
    class QLabel;
    class QLineEdit;
    class QPushButton;
    class findtest;

    class findtest : public QDialog
    {
    Q_OBJECT

    public:

    findtest(QWidget *parent = 0);
    

    signals:

    void findNext(const QString &str,Qt::CaseSensitive cs);
    void findPrevious(const QString &str,Qt::CaseSensitive cs);
    

    private slots:

    void findClicked();
    void enableFindButton(const QString &text);
    

    private:

    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;
    

    };
    #endif // FINDTEST_H
    @
    aqui esta erro error: C2061: syntax error : identifier 'CaseSensitive'



  • Hum.... estranho. Fiz um Ctrl+C Ctrl+V num arquivo .h, e não deu erro algum.

    Testei no QtCreator 2.6.2, com o Qt 4.8.3 (Linux).

    Que versão do Qt você está usando? O erro dá no .h ou no .cpp? Está usando o QtCreator, ou apenas o qmake para o build?

    Talvez o log de compilação ajude.



  • Header #ifndef FINDTEST_H
    @#define FINDTEST_H
    #include<QCheckBox>
    #include<QLabel>
    #include<QLineEdit>
    #include<QPushButton>
    #include<QString>
    #include<qnamespace.h>
    #include<Qt>* *

    #include <QDialog>
    class QCheckBox;
    class QLabel;
    class QLineEdit;
    class QPushButton;
    class findtest;

    class findtest : public QDialog
    {
    Q_OBJECT

    public:

    findtest(QWidget *parent = 0);
    

    signals:

    void findNext(const QString &str,Qt::CaseSensitive cs);
    void findPrevious(const QString &str,Qt::CaseSensitive cs);
    

    private slots:

    void findClicked();
    void enableFindButton(const QString &text);
    

    private:

    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;
    

    };
    #endif // FINDTEST_H

    #include"findtest.h"
    #include<QtCore>
    #include<QHBoxLayout>
    #include<QVBoxLayout>

    findtest::findtest(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("&Find"));

    connect(lineEdit,SIGNAL(textChanged(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->addStretch();
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);
    
    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
    

    }

    void findtest::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 findtest::enableFindButton(const QString &text)
    {
    findButton->setEnabled(!text.isEmpty());

    }

    #include "findtest.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    findtest *dialog = new findtest;
    dialog->show();
    return a.exec();
    }
    @
    error: C2061: syntax error : identifier 'CaseSensitive'



  • Esqueci que só o .h não compila. :)

    Você está usando o Qt::CaseSentive, que é o valor do enum

    @ enum CaseSensitivity {
    CaseInsensitive,
    CaseSensitive
    };
    @

    No seu código, o correto é:

    @
    signals:

    void findNext(const QString &str, Qt::CaseSensitivity cs);
    void findPrevious(const QString &str ,Qt::CaseSensitivity cs);
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.