Unsolved QTextStream confused
-
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.
-
@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 readingline = 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 -
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. -
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