![]() |
2010-09-23
, 11:13
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#122
|
I have included the QTextStream in header among others:
#include <QtCore>
#include <QMainWindow>
#include <QProgressDialog>
#include <QColorDialog>
#include <QHash>
#include <QFile>
#include <QTextStream>
But still have the errors.
![]() |
2010-09-23
, 11:21
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#123
|
Ah, funny bug:
if (!file.open (IO_ReadOnly))
// didn't work
QTextStream stream ( &file );
....
while( !stream.eof() ) {
stream is only declared in the "if-block" scope. The same like this.
if (!file.open (IO_ReadOnly))
QTextStream stream ( &file );
....
while( !stream.eof() ) {
or
if (!file.open (IO_ReadOnly))
{
QTextStream stream ( &file );
}
....
while( !stream.eof() ) {
would produce an error :-)
QFile file("/etc/hildon/theme/colors.config"); QTextStream stream ( &file ); QString line; QHash<QString, QString> variables; while( !stream.atEnd()) { line = stream.readLine(); QStringList splittedLine = line.split("="); variables.insert(splittedLine.at(0), splittedLine.at(1)); } file.close(); QString oldfont1 = variables.value("DefaultTextColor");
![]() |
2010-09-23
, 12:06
|
|
Posts: 199 |
Thanked: 156 times |
Joined on May 2010
@ Holland
|
#124
|
However the function does not work, I get nothing into QString called "oldfont1" when trying to do it like this:
Code:QFile file("/etc/hildon/theme/colors.config"); QTextStream stream ( &file ); QString line; QHash<QString, QString> variables; while( !stream.atEnd()) { line = stream.readLine(); QStringList splittedLine = line.split("="); variables.insert(splittedLine.at(0), splittedLine.at(1)); } file.close(); QString oldfont1 = variables.value("DefaultTextColor");
file.open(QFile::ReadOnly);
The Following User Says Thank You to Berserk For This Useful Post: | ||
![]() |
2010-09-23
, 12:19
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#125
|
Although I didn't see it in the above code, does it contain something like the following?
I did see some "if not opened in readonly" things in the last posts, but not an explicit .open() function.Code:file.open(QFile::ReadOnly);
Or does a QFile open the file directly after declaring it?
I thought that.. if it's not opened, nothing is read, and the QString stays empty.
The Following User Says Thank You to d-iivil For This Useful Post: | ||
![]() |
2010-09-23
, 19:25
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#127
|
Rule number one: look from API first.
Usually there are examples how to use the class, for example QFile.
![]() |
2010-09-24
, 05:34
|
Posts: 180 |
Thanked: 76 times |
Joined on May 2010
|
#128
|
Problem (for me) is that most of the docs are written in the way that the writer assumes that reader already knows how things are working and therefore they are lacking the basic guides like:
1. create QFile "object" or what ever it's called
2. you must open the file with separate command so type file.open
3. do something with the file you just opened
etc etc....
The following example reads a text file line by line:
PHP Code:
QFile file("in.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
while (!file.atEnd()) {
QByteArray line = file.readLine();
process_line(line);
}
![]() |
2010-09-24
, 09:30
|
|
Posts: 2,154 |
Thanked: 2,186 times |
Joined on Dec 2009
@ Hellsinki, Finland
|
#129
|
![]() |
2010-09-24
, 12:12
|
|
Posts: 199 |
Thanked: 156 times |
Joined on May 2010
@ Holland
|
#130
|
#include <QtCore>
#include <QMainWindow>
#include <QProgressDialog>
#include <QColorDialog>
#include <QHash>
#include <QFile>
#include <QTextStream>
But still have the errors.
If you're rich and you think I deserve a cold beer, you may donate one or two :-P
80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE