Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Need assistance from QT programmer

    Reply
    Page 11 of 18 | Prev |   9     10   11   12     13   | Next | Last
    d-iivil | # 101 | 2010-09-16, 08:09 | Report

    Originally Posted by Diph View Post
    I haven't used Designer myself, but I think it should make labels etc. automatically translatable.

    Did you try steps from here: http://doc.qt.nokia.com/qt-maemo-4.6...e-translations
    Noup, but will try it

    Edit | Forward | Quote | Quick Reply | Thanks

     
    d-iivil | # 102 | 2010-09-20, 08:57 | Report

    Okay.. translation thing is almost in order.

    Then new questions / things I cannot achieve with my (or google's) knowledge:

    I currently have this function to read directory names and then put them in QStringList:
    Code:
    void MainWindow::readdirs()
    {
        QDir colors("/opt/plastic-schemes");
        QStringList colorstobox = colors.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::DirsFirst);
        ui->Color->addItems(colorstobox);
    }
    How can I filter out unwanted directories? If I wanted to filter out directory called "Emacs", how would I do that? I couldn't find any info about excluding directories when using QDir :-(

    In terminal I would just type:
    ls | grep -v Emacs
    --------------------------------------

    Then question #2 which is more complicated:
    How could I parse html color codes from text file formatted like this and then put the parsed results in separate QStrings?:
    Code:
    DefaultTextColor=#ced0d5
    SecondaryTextColor=#ffbb45
    ActiveTextColor=#ffbb45
    DisabledTextColor=#8e8e8e
    PaintedTextColor=#1c1c1c
    
    ReversedTextColor=#141414
    ReversedSecondaryTextColor=#d29e00
    ReversedActiveTextColor=#d29e00
    ReversedDisabledTextColor=#c5c5c5
    ReversedPaintedTextColor=#ffffff
    The QString should also be given name from that file (ie. ReversedPaintedTextColor).

    That's it this time :-D

    Any good googling hits would be appreciated!

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Diph | # 103 | 2010-09-20, 10:32 | Report

    #1: I would just read all and then call colorstobox.filter() with appropriate regular expression.

    #2: Read file line by line and use QString::split to split from "=". Then put keys and values to QHash<QString,QString> if color names are unique.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to Diph For This Useful Post:
    d-iivil

     
    CepiPerez | # 104 | 2010-09-20, 12:53 | Report

    #1:
    void MainWindow::readdirs()
    {
    QDir colors("/opt/plastic-schemes");
    QStringList colorstobox = colors.entryList(QDir:irs | QDir::NoDotAndDotDot);

    for ( int i=0; i < colorstobox.count(); ++i )
    if ( colorstobox[i] != "Emacs" ) ui->Color->addItems(colorstobox);
    }

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to CepiPerez For This Useful Post:
    d-iivil

     
    d-iivil | # 105 | 2010-09-20, 14:31 | Report

    Originally Posted by CepiPerez View Post
    #1:
    void MainWindow::readdirs()
    {
    QDir colors("/opt/plastic-schemes");
    QStringList colorstobox = colors.entryList(QDir:irs | QDir::NoDotAndDotDot);

    for ( int i=0; i < colorstobox.count(); ++i )
    if ( colorstobox[i] != "Emacs" ) ui->Color->addItems(colorstobox);
    }
    Aah, ofcourse! Why didn't I figure out to use loop and if

    Thx.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Diph | # 106 | 2010-09-20, 15:24 | Report

    That loop calls ui->Color->addItems(QStringList) for every item that is not "Emacs".

    Either change the method or use temp variable where you store "non-Emacs" entries and then call addItems().

    Edit | Forward | Quote | Quick Reply | Thanks

     
    d-iivil | # 107 | 2010-09-20, 20:06 | Report

    Originally Posted by Diph View Post
    Either change the method or use temp variable where you store "non-Emacs" entries and then call addItems().
    True. Temp variable sounds like an option. Will give it a go.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    d-iivil | # 108 | 2010-09-21, 07:16 | Report

    Okay.. the question #1 is now solved and unwanted dirs are filtered out. I'm still stuck with question #2. I just don't understand the documentation good anough how to turn this:
    Code:
    DefaultTextColor=#ced0d5
    into this:
    Code:
    QString DefaultTextColor;
    DefaultTextColor = "#ced0d5";
    I'm doing the file reading like this.
    Code:
    QFile file(/etc/hildon/theme/colors.config);
    if (!file.open (IO_ReadOnly))
       // didn't work
    QTextStream stream ( &file );
    QString line;
    while( !stream.eof() ) {
         line = stream.readLine();
         <process your line and repeat>
    }
    file.close();

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Diph | # 109 | 2010-09-21, 08:56 | Report

    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();

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by Diph; 2010-09-21 at 08:59.
    The Following User Says Thank You to Diph For This Useful Post:
    d-iivil

     
    d-iivil | # 110 | 2010-09-22, 09:28 | Report

    Thanks for all help so far. I've managed to get things working pretty nice. Now I have a simple question; how can I send a QString from one slot to another? I'm pretty hopeless with all connect this and that to here and there -stuff, so please help me out :-D

    What I mean is that when program is launched, I store some info into QStrings like this:
    Code:
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        progress("Setting up the theme, please wait...", "Abort", 0, 0, this),
        colors()
    {
        ui->setupUi(this);
        ui->scrollArea->setWidget(ui->widget);
        readdirs();
        QString oldfont1 = ui->font1->text();
        QString oldfont2 = ui->font2->text();
        QString oldfont3 = ui->font3->text();
        QString oldfont4 = ui->font4->text();
    //    readSettings();
    }
    And I would like to pass those QStrings into slot when a button is clicked:
    Code:
    void MainWindow::on_pushButton_clicked()
    {
    
    }

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to d-iivil For This Useful Post:
    adhrie

     
    Page 11 of 18 | Prev |   9     10   11   12     13   | Next | Last
vBulletin® Version 3.8.8
Normal Logout