maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Need assistance from QT programmer (https://talk.maemo.org/showthread.php?t=58569)

Diph 2010-09-22 10:23

Re: Need assistance from QT programmer
 
You can use member variable to access variables in other method.

MainWindow.h
Code:

class MainWindow
{
...
private:
    QStringList fonts;
}

MainWindow.cpp
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();
    fonts.append(oldfont1);
    fonts.append(oldfont2);
    fonts.append(oldfont3);
    fonts.append(oldfont4);
//    readSettings();
}

Maybe change the method name to be more descriptive
Code:

void MainWindow::on_pushButton_clicked()
{
    fonts.at(0); //do something to oldfont1 string
}


d-iivil 2010-09-22 11:17

Re: Need assistance from QT programmer
 
1 Attachment(s)
Quote:

Originally Posted by Diph (Post 823207)
You can use member variable to access variables in other method.

MainWindow.h
Code:

class MainWindow
{
...
private:
    QStringList fonts;
}

MainWindow.cpp
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();
    fonts.append(oldfont1);
    fonts.append(oldfont2);
    fonts.append(oldfont3);
    fonts.append(oldfont4);
//    readSettings();
}

Maybe change the method name to be more descriptive
Code:

void MainWindow::on_pushButton_clicked()
{
    fonts.at(0); //do something to oldfont1 string
}


That did the trick and learned something new also, thanks :)

Now I'm strugling with QColorDialog which seems to be buggy (don't know if it's my or Qt's fault); colors shown on the palette arent matching to the actual selected color (color shown at the box on the right). You can see on the screenshot attached that on the left box I'm choosing a green color and on the right box orange is shown (and selected).

nicolai 2010-09-22 11:33

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 823242)
Now I'm strugling with QColorDialog which seems to be buggy (don't know if it's my or Qt's fault); colors shown on the palette arent matching to the actual selected color (color shown at the box on the right). You can see on the screenshot attached that on the left box I'm choosing a green color and on the right box orange is shown (and selected).

http://bugreports.qt.nokia.com/browse/QTBUG-11788

Not your fault :-)

Nicolai

d-iivil 2010-09-22 12:03

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by nicolai (Post 823255)

Oh, then I can stop figuring my way out of this :-D

Seems like they have fixed it in Qt 4.7, maybe I shall install it and see if it helps...

Edit: where the hell I can download 4.7 for Maemo? Or isn't it released yet?

CepiPerez 2010-09-22 12:23

Re: Need assistance from QT programmer
 
It's ibqt4-experimental and it's in the repositories (don't know if it's in tresting, but I'mshure its in devel).

d-iivil 2010-09-22 12:59

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by CepiPerez (Post 823276)
It's ibqt4-experimental and it's in the repositories (don't know if it's in tresting, but I'mshure its in devel).

Hmm... there's plenty of packages starting with libqt4-experimental. Installing them all via apt-get won't work, I'm getting depency issues with package libqt4-experimental-dev:
Code:

The following packages have unmet dependencies:
  libqt4-experimental-dev: Depends: libgles2-sgx-img-dev but it is not installable
                          Depends: opengles-sgx-img-common-dev but it is not installable
                          Depends: libsqlite3-dev but it is not installable

Installing all other packages one by one doesn't sound like an option to me so I went and installed just the core, but that didn't fix the colordialog -issue...

Diph 2010-09-22 15:13

Re: Need assistance from QT programmer
 
Are you sure you didn't install any other library than core and you compiled the app with Qt 4.7? I thought your app would at least need core and gui...

d-iivil 2010-09-22 17:24

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Diph (Post 823433)
Are you sure you didn't install any other library than core and you compiled the app with Qt 4.7? I thought your app would at least need core and gui...

I installed core and gui (forgot to mention the gui in last post) and yes, I re-compiled the app with 4.7 Qt Creator.

Well, anyways, that's a bit offtopic issue and will hopefully be fixed in the future (the colordialog bug).

Tomorrow I'll try to get the parse-color-codes from file -thing working and release first devel version for public use :)

d-iivil 2010-09-23 10:47

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Diph (Post 822108)
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...

nicolai 2010-09-23 10:55

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 824217)
And build errors I get are:
'IO_ReadOnly' was not declared in this cope

Use QIODevice::ReadOnly instead.
Quote:

Originally Posted by D-Iivil (Post 824217)
'stream' was not declared in this scope

maybe
#include <QTextStream>
Quote:

Originally Posted by D-Iivil (Post 824217)
'key' was not declared in this scope



All times are GMT. The time now is 23:17.

vBulletin® Version 3.8.8