Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt textfinder tutorial issue

Qt textfinder tutorial issue

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 7.3k 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.
  • C Offline
    C Offline
    Cannabis2011
    wrote on 19 Oct 2011, 20:36 last edited by
    #1

    Hello, im a little (Or a big) noob to this -QT- Qt framework, and i trying to understand how it works. I was trying the Textfinder tutorial in -QT- Qt Creator, but without any succes. I have done all the tasks, but in the end, Im getting thís error:

    @
    D:\QtSDK\Examples\TextFinder-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug..\TextFinder\textfinder.cpp:19: error: no 'void TextFinder::on_findButton_clicked()' member function declared in class 'TextFinder'
    @

    My textfinder.cpp is looking like this:

    @
    #include "textfinder.h"
    #include "ui_textfinder.h"
    #include <QtCore/QFile>
    #include <QtCore/QTextStream>

    TextFinder::TextFinder(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TextFinder)
    {
    ui->setupUi(this);
    loadTextFile();
    }

    TextFinder::~TextFinder()
    {
    delete ui;
    }

    void TextFinder::on_findButton_clicked()
    {
    QString searchString = ui->lineEdit->text();
    ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
    QMetaObject::connectSlotsByName(TextFinder);
    }

    void TextFinder::loadTextFile()
    {
    QFile inputFile(":/input.txt");
    inputFile.open(QIODevice::ReadOnly);

     QTextStream in(&inputFile&#41;;
     QString line = in.readAll();
     inputFile.close();
    
     ui->textEdit->setPlainText(line);
     QTextCursor cursor = ui->textEdit->textCursor();
     cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
    

    }
    @

    Can someone explain what i had done wrong, and i apoligize for my bad english.

    [EDIT: code formatting, please wrap in @-tags, Volker]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 19 Oct 2011, 20:43 last edited by
      #2

      You most probably forgot to add on_findButton_clicked() as a public slot in your class header file textfinder.h

      It should look something like this:

      @
      class TextFinder : public QWidget
      {

      Q_OBJECT

      public:
      // your constructors etc. here

      protected slots:
      void on_findButton_clicked();

      // ... other stuff ...
      };
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Cannabis2011
        wrote on 19 Oct 2011, 21:05 last edited by
        #3

        This is my header file:

        @
        #ifndef TEXTFINDER_H
        #define TEXTFINDER_H

        #include <QWidget>

        namespace Ui {
        class TextFinder;
        }

        class TextFinder : public QWidget
        {
        Q_OBJECT

        public:
        explicit TextFinder(QWidget *parent = 0);
        ~TextFinder();

        private slots:

        void on_FindButton_clicked();
        

        private:
        Ui::TextFinder *ui;
        void loadTextFile();
        };

        #endif // TEXTFINDER_H
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on 19 Oct 2011, 21:10 last edited by
          #4

          Again, please put @ tags around your code samples.

          (Above post edited to make @-tag correction.)

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on 19 Oct 2011, 21:11 last edited by
            #5

            on_findButton_clicked != on_FindButton_clicked

            (f vs. F in find vs. Find)

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Cannabis2011
              wrote on 19 Oct 2011, 21:14 last edited by
              #6

              Sorry, im all new to this. But it helped, thanks a lot.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on 19 Oct 2011, 21:21 last edited by
                #7

                You're welcome. Please always keep in mind that C++ (and C) are case sensitive languages, so a variable x is not the same a variable X. Also this affects the autoconnection, so you should double check the exact spelling of your widget in the UI (upper or lower case F).

                BTW: If you use Qt Creator as your IDE, just go to the header file, put the cursor on a method name and press alt-return, this will add a stub implementation in your .cpp file with all the spelling and upper/lower case done right :)

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Byro
                  wrote on 2 Aug 2012, 17:30 last edited by
                  #8

                  Hi,
                  I'm just starting too. At this point in time it seems the following will work

                  @QMetaObject::connectSlotsByName(this);@

                  The most reasonable place to place it is in the TextFinder constructor, so it looks like this:

                  @TextFinder::TextFinder(QWidget *parent) :
                  QWidget(parent),
                  ui(new Ui::TextFinder)
                  {
                  ui->setupUi(this);
                  loadTextFile();
                  QMetaObject::connectSlotsByName(this);
                  }@

                  I am not sure why would you want it in a clicked event and no one corrected you. :)

                  Using version
                  Qt Creator 2.4.1
                  Based on Qt 4.8.0 (64 bit)
                  Built on Mar 21 2012 at 22:53:22

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lypo
                    wrote on 23 Apr 2013, 09:26 last edited by
                    #9

                    [quote author="Byro" date="1343928612"]
                    The most reasonable place to place it is in the TextFinder constructor, so it looks like this:
                    @TextFinder::TextFinder(QWidget *parent) :
                    QWidget(parent),
                    ui(new Ui::TextFinder)
                    {
                    ui->setupUi(this);
                    loadTextFile();
                    QMetaObject::connectSlotsByName(this);
                    }@[/quote]

                    Yeah, thanks Byro! It works. In the Tutorial is not written where to place the QMetaObject::
                    Also they want the className "TextFinder" - this dosn't work.

                    This is my first work with Qt - I looked for the mistake half the night. :-(
                    Now I'm HAPPY!

                    @Volker: Thanks for your advice! Sounds very useful. :-)

                    Sorry, I hope you'll understand my bad english - had been a bad teacher in school - 43 years ago. :-)

                    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