Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How can I do a bit shift in Qt? The analogue in c++ is presented bellow as a part of code:
@while(file >> i)
Thanks in advance.
koahnig last edited by
Qt libs are usually used with C++. So you can do this as you do in C++.
Or do you mean something specific?
The special staff is that in Qt file is @QFile@ and i is @int@
You are not very clear. Are you trying to get data from a file or do bit shifting ?
I am trying to calculate the elements in the file. For more clarity see the code below:
int numberOfElements = 0;
QMessageBox::warning(0, "Error", file.errorString());
while(file >> fileIterator)
The code provided is wrong and I realize it, as >> is from fstream (if I loaded the file with standard c++ as follows ifstream file(filename); there would be no problem), as I load the file using QFile it means that file >> fileIterator is impossible w.r.t the following error about types inequality:
bq. error: no match for 'operator>>' (operand types are 'QFile' and 'int')
Q: How can I make >> in my case to work? Any suggestion? Alternatives?
Since it's a csv, you have a file text you could use "QTextStream":http://qt-project.org/doc/qt-4.8/qtextstream.html.
But, if I have understood you correctly you want to count all the elements contained in your csv. You could read your file line by line in a QString, and use split with the delimiter to get the actual count of the elements per line.
Buckets last edited by
create a subclass of QFile with the bit shift operators.
An easier way to get the count of either lines, or entries per line would do what SGaist suggested where you read the file in line by line into multiple buffers or the whole file into one giant buffer. Then use QString's split function with either the , or \n as your delimiter. The split function returns a QStringList which contains a count.