Questions tagged [qtextstream]

The QTextStream class provides a convenient interface for reading and writing text.

QTextStream can operate on a QIODevice, a QByteArray or a QString. Using QTextStream's streaming operators, you can conveniently read and write words, lines and numbers. For generating text, QTextStream supports formatting options for field padding and alignment, and formatting of numbers.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

90 questions
7
votes
5 answers

QTextStream behavior searching for a string not as expected

I have these few lines of code: QFile file("h:/test.txt"); file.open(QFile::ReadOnly | QFile::Text); QTextStream in(&file); bool found = false; uint pos = 0; do { QString temp = in.readLine(); int p = temp.indexOf("something"); if (p <…
dtech
  • 47,916
  • 17
  • 112
  • 190
5
votes
2 answers

Peek on QTextStream

I would like to peek the next characters of a QTextStream reading a QFile, in order to create an efficient tokenizer. However, I don't find any satisfying solution to do so. QFile f("test.txt"); f.open(QIODevice::WriteOnly); f.write("Hello…
FabienRohrer
  • 1,794
  • 2
  • 15
  • 26
4
votes
2 answers

In Qt: Can I output to `stdout`, as easy as I can output to `stderr` using qDebug()?

Up until now, I output everything using qDebug().noquote(). This is easy because it just requires a simple #import Now I need everything to output to stdout, but I don't know how to do it easily. This how I was taught: QTextStream…
Anon
  • 2,267
  • 3
  • 34
  • 51
4
votes
1 answer

Why am I getting a crash using QTextStream on an open FILE *

I'm on windows, qt 4.7. part of my code takes a FILE* from a file which is open for reading by another part of the system (legacy, C). I open a QTextStream as follows: // file currently opened (readonly), and partially read FILE *infile =…
mike
  • 1,192
  • 9
  • 32
4
votes
2 answers

QTextStream atEnd() is returning true when starting to read from a file

I want to read and parse contents of the /proc/PID/status file on a linux machine, but the QTextStream.atEnd is always returning true when starting to read. The code: QString procDirectory = "/proc/"; procDirectory.append(QString::number(PID)); …
user2195430
  • 105
  • 1
  • 8
3
votes
1 answer

Qt (C++): QFile creates text file successfully but does not write to it

I have the following code, with which I am attempting to write to a file. When it is called, the file is created in the directory and the for-loop is entered. The values for in QVector program also exist and are visible with qDebug(). However,…
Jordan
  • 97
  • 2
  • 11
3
votes
3 answers

QTextStream read a string until tab

I have filenames that have space in them, but are separated by tabs. How can I read them one by one using a QTextStream? The normal way would split by tabs AND spaces (actually any QChar::isSpace()), which is not what I want here: QString s = "file…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
3
votes
2 answers

Qt - Writing a file with QTextStream adds empty new lines to the text

I'm using the following code to write some text to a file: QFile caFile(outputFolder + "file.extension"); caFile.open(QIODevice::WriteOnly | QIODevice::Text); if(!caFile.isOpen()){ qDebug() << "- Error, unable to open" << "outputFilename" <<…
Alaa Salah
  • 1,047
  • 3
  • 12
  • 28
3
votes
1 answer

Qt compile error: endl will always evaluate to true

I have the following code snippet that compiles QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); for (QStringList::Iterator it = commandList.begin(); it != commandList.end(); ++it) { out << "Command: " << *it << endl; } but…
TSG
  • 4,242
  • 9
  • 61
  • 121
2
votes
1 answer

Qt: Writing umlaut to file

I am trying to store the contents of a QDomDocument to a file. The document contains a German umlaut, which doesn't get saved to the file correctly. My QDomDocument "document" is structured like this:
Don Joe
  • 274
  • 4
  • 13
2
votes
1 answer

Qt console: Log all stdin and stdout to file

I have a Qt console application. All communication with the user goes over two streams: QTextStream in(stdin); QTextStream out(stdout); Now I want to log the whole session to a file, but I don't want to add a log output on every location where the…
Thomas Klier
  • 449
  • 4
  • 16
2
votes
1 answer

QTextStream messing its position pointer

I'm writing a parser for a text file, but QTextStream seems to be missing something. I'm using Qt 5.4.1, and the code is single-threaded, if that matters. This is the method: const Event* AviLogFile::nextEvent() { …
Vitor
  • 2,734
  • 29
  • 40
2
votes
0 answers

Convert QTextStream to std::stringstream

I have a few text files embedded in a .qrc file. However, my back-end project is not based on Qt and a couple of times in the Qt front-end project, I have to call A::read(std::string const& filePath)-like functions that utilize std::ifstream to read…
LogicStuff
  • 19,397
  • 6
  • 54
  • 74
2
votes
2 answers

Writing a QVector to a text file in Qt

I'm trying to write a program which reads in a text file containing several rows of 512 elements. These are numbers separated by a tab, the first line of the file contains general info about the file itself. Here's what it looks like: 512…
Mitchell D
  • 465
  • 8
  • 24
2
votes
2 answers

QTextStream formatting issue

I am trying to use a QTextStream to format numerical output. I've simplified my issue into a little test program to demonstrate my problem. Following is my code: #include #include #include int main(int…
roundtheworld
  • 2,651
  • 4
  • 32
  • 51
1
2 3 4 5 6