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. QTextStream confused

QTextStream confused

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k 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.
  • ChukkC Offline
    ChukkC Offline
    Chukk
    wrote on last edited by
    #1

    Hey there,
    I'm new and just started learning QT. i have basic c++ skills, so i thought i shoud give it a try. Everything is working fine. Im a little scared of qml because i like stl and everything is a bit weird, but i like how i just need a minute to create a window and all t hat stuff.
    but this is not why im here.

    Im writing a Programm and i use the tablewidget to manage some values.
    I also save the files in a text file and it works fine. now i also want to delete
    rows of the tablewidget and overwrite the old textfile with the new row values.
    i think im getting there but something makes no sense to me.
    I work with QStringStreams and QStrings. at one Point.
    i compare two QStrings. but no matter if i type == or !=
    its always the same result.

    I hope this code is enough (its not all but everything that does something with those two QStrings). i changed two labels to see the results.
    Just for a test and both labels always change (if i compare with != and ==).

    Im not the best thinker, but i usually find a solution in the end. So for this one i need you guys or girls.

    I really hope you can work with this. As far as i know... something that is equal should never pass as not equal or did i do something to breake rules of QT-Land.

    //my code here
    QString search_me="";
    QString line="";
    QTextStream in(&Datei); // <- Datei is the file im reading
    
    line = in.readLine();
    
    ui->label_2->setText(line);
    // this
    if (line != search_me)ui->label->setText(search_me);
    // and this
    if (line == search_me)ui->label->setText(search_me);
    // they both always 'pass' 
    // i tested both individually
    

    I hope my english isnt to bad to understand what i want . I usually just read or watch stuff in english.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      @Chukk said:

      I think the problem is in how you define "passed"
      Print out messages in each if statement and you should see only one in output

      #include <QDebug>

      //my code here
      QString search_me="";
      QString line="";
      QTextStream in(&Datei); // <- Datei is the file im reading

      line = in.readLine();

      ui->label_2->setText(line);
      // this
      if (line != search_me)
      {
      ui->label->setText(search_me);
      qDebug() << "line != search_me";
      }
      // and this
      if (line == search_me)
      {
      ui->label->setText(search_me);
      qDebug() << "line == search_me";
      }
      // they both always 'pass'
      // i tested both individually

      1 Reply Last reply
      0
      • ChukkC Offline
        ChukkC Offline
        Chukk
        wrote on last edited by
        #3

        Thank you. It works now. But could you maybe explain why this happend ?
        If not i will try to find out for myself. Maybe its just to late (2 am over here).
        Well at least it works like it should.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          I think you were confused by debugger.
          Code as it was should work,
          Debugger stops/executes by at least 1 line.

          you put if statement and function call in the same row:
          if (line == search_me) ui->label->setText(search_me);
          so it is not easy to see in the debugger if setText was executed

          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