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
2
votes
1 answer

Qt is successfully creating a file but not writing to it with QTextStream

Hey I'm trying to mess around with Qt and for some reason the following code will create the desired text file, but never writes anything to it. Am I doing something wrong? I believe I've copied the example in the documentation pretty accurately.…
druckermanly
  • 2,694
  • 15
  • 27
1
vote
1 answer

How to write binary data to stdout in Qt5

QTextStream allows me to wrap stdout so that I can write using Qt spesifics to stdout with conveneince. Example: QTextStream qout(stdout); qout << QString("Some qt spesific stuff: %1\n").arg(1337); However while QTextStream is really useful, it…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
1
vote
0 answers

QtMessageHandler / QTextStream causes memory usage to go up?

I have installed a simple QtMessageHandler in my application: void handleMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString text = msg; QString path = QCoreApplication::applicationDirPath() +…
Don Joe
  • 274
  • 4
  • 13
1
vote
1 answer

Qt program to read text sees only one line in multi-line file

I wrote a program to read a sequence of integer scores one per line in a text file. The file has a header which needs to be skipped. Despite staring at this program, it only sees the first line (the header) and then behaves as if it's at the end.…
user1741137
  • 4,949
  • 2
  • 19
  • 28
1
vote
2 answers

How to "write" backspace in QTextStream?

I am writing a simple CSV export of data using QTextStream but a redundant comma appears at the end of each row. How can I delete the last written symbol in the QTextStream and continue writing data after deleting?
Uga Buga
  • 1,724
  • 3
  • 19
  • 38
1
vote
1 answer

QTextStream fixed point formatting issue

I'm having an issue with the QTextStream formatting. I'm using the code below to print a percentage from a quint8 and it seems to be giving me a space in between the number and the decimal point. For example, I'll get "50 %" instead of "50%" and…
kjgregory
  • 656
  • 2
  • 12
  • 23
1
vote
1 answer

QFile init/assignment op issue when objects are class members

So i have a QFile and QTextStream member as part of my class... trying to init. them together in my constructor: Class.h: QFile _file; QTextStream _textstrm; Class.cpp: _file = QFile (/*file name*/); _file.open(/*set stuff*/); _textstrm =…
Mike
  • 190
  • 7
1
vote
1 answer

Qt simple error when trying to delete a word in QTextEdit

I'm trying to delete a word after pressing space on a QTextEdit. Here's my code: window.h: #ifndef WINDOW_H #define WINDOW_H #include #include #include #include using namespace std; class Window:…
David
  • 25
  • 3
1
vote
1 answer

QTextEdit append issue

I want to read some text from file and display in QTextEdit. File is about 2 MB. I have created QObject class and connect signals and slots with thread. The problem is it still freezes window even when the thread is running. My code: QObject…
Cobra91151
  • 610
  • 4
  • 14
1
vote
0 answers

Truncate file when closed (Qt)

Using Qt, I am opening a file for read-write access, first reading some content, then seeking back in the stream and writing some new data. When I close the file, I'd like to truncate it at the current file position. Currently, I do it with a…
user52366
  • 1,035
  • 1
  • 10
  • 21
1
vote
2 answers

Unwanted character in CSV file when serializing from QTableWidget

I am trying to read data from a QTableWidget, and save them in a CSV file. The values saved in the file are correct, but for the first column in every row there is an unwanted character in the beginning. Here is my code: void…
Vishal Khemani
  • 171
  • 2
  • 13
1
vote
2 answers

PyQt5: cannot write cookie to file using QFile

I have a file named cookies.txt. fd = QFile(":/cookies.txt") available_cookies = QtNetwork.QNetworkCookieJar().allCookies() for cookie in available_cookies: print(cookie.toRawForm(1)) QTextStream(cookie.toRawForm(1),…
wrufesh
  • 1,379
  • 3
  • 18
  • 36
1
vote
2 answers

QFile ignoring last newline

I'm using Qt to read a file std::vector text; QFile f(file); if (f.open(QFile::ReadWrite | QFile::Text) == false) throw my_exception(); QTextStream in(&f); QString line; while(!in.atEnd()) { line = in.readLine(); …
Dean
  • 6,610
  • 6
  • 40
  • 90
1
vote
2 answers

QTextStream - What exactly does the position method return

I have a question about what a QTextStream is calculating with the pos() method. I assumed it was the number of bytes, but it seems that this might not be the case. The reason I ask, is that I am processing rows in a file, and once the number of…
1
vote
0 answers

Does a QtextStream::readAll() flushes my QTextStream object?

I filled my QtextStream textStream object, already. When it does not end with an "}", I want to append one "}" in that case: QString fullText = textStream.readAll(); if( !fullText.trimmed().endsWith("}") ) { QString lastBracket("\n}"); …
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103