View Single Post
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#119
Originally Posted by Diph View Post
Store the items in QHash. Then you can access items by key: QHash::value(const Key & key)

Code:
QFile file(/etc/hildon/theme/colors.config);
if (!file.open (IO_ReadOnly))
   // didn't work
QTextStream stream ( &file );
QString line;
QHash<QString, QString> variables;
while( !stream.eof() ) {
     line = stream.readLine();
     //Split
     QStringList splittedLine = line.split("=");
     //Maybe add some checks here (splittedLine.count == 2 etc.)
     variables.insert(splittedLine.at(0), splittedLine.at(1)); 
}
file.close();
Still need some help with this :-(

My code (mainwindow.cpp) looks now like this:
Code:
    QFile file("/etc/hildon/theme/colors.config");
    if (!file.open (IO_ReadOnly))
       // didn't work
    QTextStream stream ( &file );
    QString line;
    QHash<QString, QString> variables;
    while( !stream.eof() ) {
         line = stream.readLine();
         //Split
         QStringList splittedLine = line.split("=");
         //Maybe add some checks here (splittedLine.count == 2 etc.)
         variables.insert(splittedLine.at(0), splittedLine.at(1));
    }
    file.close();
    QString oldfont1 = variables.value(key.DefaultTextColor());
And build errors I get are:
'IO_ReadOnly' was not declared in this cope
'stream' was not declared in this scope
'key' was not declared in this scope

I propably didn't quite understand how QHash works so the last line of my code might be totally wrong too...
__________________
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