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 Problem
Forum Updated to NodeBB v4.3 + New Features

Qt TextFinder Tutorial Problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 2.9k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    Hailo90
    wrote on 3 Jan 2014, 21:09 last edited by
    #1

    Hello,

    I found the tutorial for Qt and just tried to copy that and understand it.

    I thought I made everything right, but obviously not, because when I run the code the Application starts with these lines:

    bq. In German:
    Starte C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe...
    QIODevice::read: device not open
    C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe beendet, Rückgabewert 0

    i think in english it should look like:

    bq. Run C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe...
    QIODevice::read: device not open
    C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe terminate/exit, return 0

    My Files:

    textfinder.h

    @#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
    @

    textfinder.cpp
    @#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();
    QMetaObject::connectSlotsByName(this);
    }

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

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

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

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

    }
    @

    so how do i fix it?

    W 1 Reply Last reply 9 Dec 2015, 20:30
    0
    • S Offline
      S Offline
      steno
      wrote on 3 Jan 2014, 21:26 last edited by
      #2

      You're reading from an io device that isn't opened. Did you make sure the open call on inputeFile isn't failing?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 3 Jan 2014, 22:26 last edited by
        #3

        Hi and welcome to devnet,

        Do you have input.txt in your sources and do you have a qrc file referencing it in your project ?

        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
        • H Offline
          H Offline
          Hailo90
          wrote on 4 Jan 2014, 18:08 last edited by
          #4

          bq. You’re reading from an io device that isn’t opened. Did you make sure the open call on inputeFile isn’t failing?

          How can I make it sure, that the open call isn't failing?

          bq. Hi and welcome to devnet,
          Do you have input.txt in your sources and do you have a qrc file referencing it in your project ?

          I have a resource file (name: textfinder.qrc) with the prefix / and a file in it with the name input.txt.

          When i double click the resource file I see on top the / and below the input.txt

          I even found the file on my drive

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 4 Jan 2014, 21:07 last edited by
            #5

            By solving what error QFile returns if open fails

            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
            • H Hailo90
              3 Jan 2014, 21:09

              Hello,

              I found the tutorial for Qt and just tried to copy that and understand it.

              I thought I made everything right, but obviously not, because when I run the code the Application starts with these lines:

              bq. In German:
              Starte C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe...
              QIODevice::read: device not open
              C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe beendet, Rückgabewert 0

              i think in english it should look like:

              bq. Run C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe...
              QIODevice::read: device not open
              C:<PathToProjectFolder>\Qt\build-TextFinder-Desktop_Qt_5_2_0_MSVC2012_OpenGL_64bit-Debug\debug\TextFinder.exe terminate/exit, return 0

              My Files:

              textfinder.h

              @#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
              @

              textfinder.cpp
              @#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();
              QMetaObject::connectSlotsByName(this);
              }

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

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

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

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

              }
              @

              so how do i fix it?

              W Offline
              W Offline
              Wodzu
              wrote on 9 Dec 2015, 20:30 last edited by
              #6

              @Hailo90 You need to firt "Run qmake" before running the project.

              As above so below...

              1 Reply Last reply
              1

              • Login

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