Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED] Qt beginner question: findNext and findPrevious "identifier not found"
QtWS25 Last Chance

[SOLVED] Qt beginner question: findNext and findPrevious "identifier not found"

Scheduled Pinned Locked Moved Installation and Deployment
6 Posts 2 Posters 5.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tom_q
    wrote on last edited by
    #1

    Dear all,

    This is my first post here, apologies for formatting mistakes or similar things. I'm trying to compile and run one of the first examples from the book "C++ GUI Programming with Qt 4". I'm using an up-to-date Qt Creator 2.7.0, based on Qt 5.0.2 (32 bit), all running on a Windows 8 (shame on me) machine. Everything is out of a fresh install; my understanding is that it should work fine without further configuration, although I have some doubts. Simpler Qt applications (previous examples in the book) run fine in this configuration.

    I tried Build->Clean All, Build->Run qmake, Build->Build Project. I initially got many errors as apparently "#include<QtGui>" didn't work as intended; but I could solve most errors by including all the relevant classes. I have two errors left:
    @error: C3861: 'findPrevious': identifier not found
    error: C3861: 'findNext': identifier not found@

    If I comment out the lines producing the error, the program compiles, but crashes:
    @Starting C:\Qt\Qt502\Tools\QtCreator\bin\build-QtTest-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug\debug\QtTest...
    The program has unexpectedly finished.
    C:\Qt\Qt502\Tools\QtCreator\bin\build-QtTest-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug\debug\QtTest exited with code -1073741819@

    The complete code should be identical to that in the book (except I used "testdialog" instead of "finddialog" and had to add a bunch of includes), and is as follows:
    main.cpp:
    @
    #include <QApplication>
    #include "testdialog.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    TestDialog *dialog = new TestDialog(0);
    dialog->show();
    return a.exec();
    }
    @

    textdialog.h:
    @
    #ifndef TESTDIALOG_H
    #define TESTDIALOG_H

    #include <QDialog>

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

    class TestDialog : public QDialog
    {
    //Provides ~events/delegates (SIGNALS/SLOTS) with qmake.
    Q_OBJECT

    public:
    explicit TestDialog(QWidget *parent = 0);

    signals:

    public slots:

    private slots:
    void testClicked();
    void enableTestButton(const QString &text);

    private:
    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *testButton;
    QPushButton *closeButton;
    };

    #endif // TESTDIALOG_H
    @

    testdialog.cpp:
    @
    #include <QtGui> //Doesn't seem to work. I get errors for basically every class. Had to "manually" include each class.
    #include <QCheckBox>
    #include <QLabel>
    #include <QLineEdit>
    #include <QPushButton>
    #include <QHBoxLayout>
    #include <QVBoxLayout>
    #include <QString>
    #include "testdialog.h"

    TestDialog::TestDialog(QWidget *parent) :
    QDialog(parent)
    {
    label = new QLabel(tr("Find &what:"));
    label->setBuddy(lineEdit);
    caseCheckBox = new QCheckBox(tr("Match &case"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));

    testButton = new QPushButton(tr("&Find"));
    testButton->setDefault(true);
    testButton->setEnabled(false);
    
    closeButton = new QPushButton(tr("Close"));
    
    connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableFindButton(const Qstring &)));
    connect(testButton, SIGNAL(clicked(const QString &)), 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(testButton);
    rightLayout->addWidget(closeButton);
    rightLayout->addStretch();
    
    QHBoxLayout *mainLayout = new QHBoxLayout();
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);
    
    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
    

    }

    void TestDialog::testClicked()
    {
    QString text = lineEdit->text();
    Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    if(backwardCheckBox->isChecked())
    {
    emit findPrevious(text, cs); //error 1
    }
    else
    {
    emit findNext(text, cs); //error 2
    }
    }

    void TestDialog::enableTestButton(const QString &text)
    {
    testButton->setEnabled(!text.isEmpty());
    }
    @

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You didn't declare findPrevious nor findNext in your signals.

      And since you're on Qt5 with code from Qt4 did you add

      @QT += widgets@

      To your pro file ?

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tom_q
        wrote on last edited by
        #3

        I feel stupid for missing the signals declaration; I just assumed that somehow these specific signals were included in Qt. The program now compiles fine, although it still crashes once compiled. I'll look into why it crashes before I call this "solved", might be something as simple as what you just mentioned. Thanks!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I would say: lineEdit not initialized before you use it

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tom_q
            wrote on last edited by
            #5

            @SGaist: yeah, I actually figured it out on my own. So as expected, another stupid mistake, and here I was trying to figure out if the Qt installation was messed up... Anyway, thanks! Solved.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Your welcome !

              Don't forget the debugger, he's (almost) always your friend :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved