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. [Solved] Error with Qtextstream And Bool
Forum Updated to NodeBB v4.3 + New Features

[Solved] Error with Qtextstream And Bool

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.5k 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.
  • R Offline
    R Offline
    Raminlich
    wrote on last edited by
    #1

    @{
    QString srch,cr;
    QFile mys("e:/mystock.txt");
    if(mys.open(QIODevice::ReadOnly | QIODevice::Text)){
    QTextStream out(&mys);
    bool found = false;
    while(out>>names){
    if(srch==names)
    {
    ui->groupBox_3->show();
    found = true;

    }
                   if(!found){
                       QMessageBox msg;
                       msg.setText("Company Not Found");
                       msg.exec();
    

    }
    }
    }
    }@
    says:
    error: could not convert 'out.QTextStream::operator>>((* & names))' from 'QTextStream' to 'bool'
    while(out>>names){
    ^

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      out>>names does not evaluate to Boolean. It is QTextStream and does not get evaluate to bool. You can't put this as condition check. What is your intent to put this check ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Raminlich
        wrote on last edited by
        #3

        in another function program will write some info on the txt file in this i want to check if the info that you enter is correct the program will continiue here is full code And thanks for your replay
        @#include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QFile>
        #include <QTextStream>
        #include <QMessageBox>
        using namespace std;
        QString names;
        QFile mys("e:/mystock.txt");
        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        ui->groupBox_3->hide();

        }

        MainWindow::~MainWindow()
        {
        delete ui;

        }

        void MainWindow::on_pushButton_clicked()
        {
        QString name;
        int d,m,sd,amount;

        name=ui->lineEdit_name->text();
        amount=ui->lineEdit_amount->text().toInt();
        d=ui->lineEdit_d->text().toInt();
        m=ui->lineEdit_m->text().toInt();
        sd=ui->lineEdit_y->text().toInt();
        
        if(mys.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)){
            QTextStream input(&mys);
             names=name;
        input<<names<<" "<<amount<<"    "<<d<<"/"<<m<<"/"<<sd;
        

        }

        }

        void MainWindow::on_pushButton_2_clicked()
        {
        QString srch,cr;
        if(mys.open(QIODevice::ReadOnly | QIODevice::Text)){
        QTextStream out(&mys);
        bool found = false;
        while(out>>names){
        if(srch==names)
        {
        ui->groupBox_3->show();
        found = true;

        }
                       if(!found){
                           QMessageBox msg;
                           msg.setText("Company Not Found");
                           msg.exec(&#41;;
        

        }

        }
        }
        }

        void MainWindow::on_actionExit_triggered()
        {
        close();
        }@
        is there any other way to check?

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          I'm not sure why are using the file store and check this logic. By looking at the logic, you would like to check on the all the parameter entered ? Hope it is correct. You can use QFile.readLine. Split them in the form of tokens using QString.split. This returns the tokens in the form of StringList. You can iterate over each of them and check it.

          You can try something like the below.

          @ QFile file("my.dat");
          file.open(QIODevice::ReadOnly);
          QString line = file.readLine();
          QStringList tokens = line.split(" ");
          int count = tokens.size();
          for(int i=0;i<count;i++){
          QString token = tokens.at(i);
          qDebug() << "Token=" << token;
          }@

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Raminlich
            wrote on last edited by
            #5

            unfortunately no i only want to check one of them like
            if the .txt file be like this
            ramin 100 8/8/2012
            i only want check is ramin or not :)
            thanks

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              In that case

              @QString name = tokens.at(0)
              if (name.compare("ram in") == 0 )
              exist
              else
              does not exist@

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Raminlich
                wrote on last edited by
                #7

                thank u for your quick reply

                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