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)

d-iivil 2010-09-23 11:04

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by nicolai (Post 824226)
Use QIODevice::ReadOnly instead.

maybe
#include <QTextStream>

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.

nicolai 2010-09-23 11:13

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 824235)
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.

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 :-)

d-iivil 2010-09-23 11:21

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by nicolai (Post 824243)
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 :-)

function 'stream' does not have a member 'eof' :-P

So I tried this:
while( !stream.atEnd())

And got no errors. 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");


Berserk 2010-09-23 12:06

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 824249)
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");


Although I didn't see it in the above code, does it contain something like the following?
Code:

file.open(QFile::ReadOnly);
I did see some "if not opened in readonly" things in the last posts, but not an explicit .open() function.

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.

d-iivil 2010-09-23 12:19

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Berserk (Post 824294)
Although I didn't see it in the above code, does it contain something like the following?
Code:

file.open(QFile::ReadOnly);
I did see some "if not opened in readonly" things in the last posts, but not an explicit .open() function.

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.

Hallelujah! It's working now :)
I thought it opens the file automaticly, but obviously it didn't :)

Diph 2010-09-23 12:37

Re: Need assistance from QT programmer
 
Rule number one: look from API first. :)

Usually there are examples how to use the class, for example QFile.

d-iivil 2010-09-23 19:25

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Diph (Post 824321)
Rule number one: look from API first. :)

Usually there are examples how to use the class, for example QFile.

I actually do use the "F1" -key very often inside Qt Creator and really try to find the answers first from docs before asking here :)

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....

But I'm slowly learning and thanks to you guys for answering my questions over and over gain.

Diph 2010-09-24 05:34

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 824669)
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....

Quote:

Originally Posted by QFile Class Reference
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);



Sorry for this. :P

d-iivil 2010-09-24 09:30

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Diph (Post 824943)
Sorry for this. :P

Yep, I noticed the example but they did not explain what happens line by line which is necessary for an idiot like me :D

Anyways, it's now working and getting closer to first release :)

Berserk 2010-09-24 12:12

Re: Need assistance from QT programmer
 
What do you not understand exactly?

In the example they don't use QTextStream::readLine(), they use QFile::readLine(), which is inherited from QIODevice.

The difference is that QTextStream::readLine() returns a QString and QFile::readLine() returns a qint64 (QByteArray in the example), but I don't know anything about qint64 or QByteArrays, so I'll stick with QTextStrem::readLine() :p

d-iivil 2010-09-24 12:57

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Berserk (Post 825143)
What do you not understand exactly?

In the example they don't use QTextStream::readLine(), they use QFile::readLine(), which is inherited from QIODevice.

The difference is that QTextStream::readLine() returns a QString and QFile::readLine() returns a qint64 (QByteArray in the example), but I don't know anything about qint64 or QByteArrays, so I'll stick with QTextStrem::readLine() :p

I understand it now, but when I first checked the example and didn't have a glue that I should use file.open I didn't pay attention to the example enough :)

Anyways... next "problem" is to read gconf -values and since Qt Creator doesn't support it natively and documentation is really poor on that area, I think I'm gonna have no spare time problems this weekend...

Berserk 2010-09-24 13:31

Re: Need assistance from QT programmer
 
Oh I'm sorry, I thought it was your current question, I read it wrong :p

But I'd also like to know that gconf thing :D I want to make an Install function in my Wallpaeper app, so people don't have to use the desktop settings anymore.

This seems to be something about GTK+ for Qt, haven't read it, gotta go again :p
http://ubuntuforums.org/showthread.php?t=1270124

d-iivil 2010-09-24 14:44

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Berserk (Post 825205)
Oh I'm sorry, I thought it was your current question, I read it wrong :p

But I'd also like to know that gconf thing :D I want to make an Install function in my Wallpaeper app, so people don't have to use the desktop settings anymore.

This seems to be something about GTK+ for Qt, haven't read it, gotta go again :p
http://ubuntuforums.org/showthread.php?t=1270124

Here's some info about it:
http://maemo.gitorious.org/~vivainio...nf/gconfitem.h

But once again I don't even know where to start with that. No matter what I write in the source I cannot make Qt Creator to build it...

Berserk 2010-09-25 15:56

Re: Need assistance from QT programmer
 
That page is linked from:
http://wiki.forum.nokia.com/index.ph...pers_for_GConf

The GConfItem looks like a great object to me, easy to use too, but I don't know what I should #include, maybe it needs another entry in the .pro file, just like QMaemo5InformationBox needs QT += maemo5..

The example on this page uses GConfItem:
http://wiki.forum.nokia.com/index.ph...th_Qt_Mobility

I've tried a few things, but Qt keeps telling me "GConfItem is not a type name" :(


Can somebody please clarify this GConfItem object? :D

Diph 2010-09-25 16:11

Re: Need assistance from QT programmer
 
Have you added these lines to .pro file?

Code:

CONFIG += link_pkgconfig
PKGCONFIG += gq-gconf


d-iivil 2010-09-25 17:02

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Berserk (Post 826067)
That page is linked from:
http://wiki.forum.nokia.com/index.ph...pers_for_GConf

The GConfItem looks like a great object to me, easy to use too, but I don't know what I should #include, maybe it needs another entry in the .pro file, just like QMaemo5InformationBox needs QT += maemo5..

The example on this page uses GConfItem:
http://wiki.forum.nokia.com/index.ph...th_Qt_Mobility

I've tried a few things, but Qt keeps telling me "GConfItem is not a type name" :(


Can somebody please clarify this GConfItem object? :D

If you get it working, please share with me how to just read a gconf value. That's all I need :)

Berserk 2010-09-25 17:22

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Diph (Post 826077)
Have you added these lines to .pro file?

Code:

CONFIG += link_pkgconfig
PKGCONFIG += gq-gconf


Yes :)
I also did a 'GConfItem' search on my NokiaQtSDK directory, but it found nothing.
It does have some gconf headers that I can include, but even when I included all of them, it still doesn't recognise GConfItem :(
The auto-complete feature of Qt Creator is a great way of seeing which headers can be included in this case :)

Do I need to install some additional packages for the Nokia Qt SDK?

Apparently this:
http://maemo.gitorious.org/~vivainio/maemo-af/libgq-fremantle/blobs/master/gconf/gconfitem.h
has to go into an include dir.. ?

Berserk 2010-09-25 17:49

Re: Need assistance from QT programmer
 
http://maemo.org/packages/view/libgq-gconf-dev/
It wouldn't install on Windows, but we're getting close :p

Diph 2010-09-25 18:18

Re: Need assistance from QT programmer
 
Install lib in scratchbox armel target and make links of gconf lib and include files under usr and place them in NokiaQtSDK Maemo usr/lib and usr/include.

Berserk 2010-09-26 17:35

Re: Need assistance from QT programmer
 
Thanks, but I don't quite understand it..
I'm using Madde on a WinXP system, so I guess that makes things different? :p

d-iivil 2010-09-30 10:08

Re: Need assistance from QT programmer
 
Hi again guys.

I need some help with validating user input and then do actions based on if the input is valid or not.

So far I'm good with validating the input, the validator allows me only to input correctly formatted stuff. What it doesn't check is if the input length is enough. What I don't know is how to know later if the input was long enough or not.

Here's what I do when program launches (I create the validator and set it to line edits):
Code:


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    progress(tr("Setting up the theme, please wait..."), tr("Abort"), 0, 0, this),
    progress2(tr("Searching and importing fonts, please wait..."), tr("Abort"), 0, 0, this),
    colors()
{
    ui->setupUi(this);
    ui->scrollArea->setWidget(ui->widget);
    readdirs();
    oldfonts();
    readSettings();
    QRegExp regexer("\\#[0-9a-fA-F]{6,6}");
    QValidator* actualvalidator;
    actualvalidator = new QRegExpValidator(regexer, this);
    //QRegExpValidator validator();
    ui->line_edit_font1->setValidator(actualvalidator);
    ui->line_edit_font2->setValidator(actualvalidator);
    ui->line_edit_font3->setValidator(actualvalidator);
    ui->line_edit_font4->setValidator(actualvalidator);
    ui->line_edit_font5->setValidator(actualvalidator);
    ui->line_edit_font6->setValidator(actualvalidator);
}

How can I check in some slot later if the input is valid and if it's not, then do some actions. Like:
Code:

void MainWindow::on_line_edit_font1_editingFinished()
{

if ( user inputted seven characters, which is valid ) {

// do something with the valid input

} elseif ( user inputted only four characters which is INVALID ) {

// tell user he's bad and he should write only valid things...

}

}


nicolai 2010-09-30 10:35

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 829954)
Code:

void MainWindow::on_line_edit_font1_editingFinished()
{

if ( user inputted seven characters, which is valid ) {

// do something with the valid input

} elseif ( user inputted only four characters which is INVALID ) {

// tell user he's bad and he should write only valid things...

}

}



Code:

if (ui->line_edit_font1->text().length() == 7) {

// do something with the valid input

} elseif (ui->line_edit_font1->text().length() == 4) {

// tell user he's bad and he should write only valid things...

}

But how can the user enter invalid short text?
I don't know how this qtvalidator work, but isn't that
enough to prevent the short text?
regards
Nicolai

d-iivil 2010-09-30 10:39

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by nicolai (Post 829975)
Code:

if (ui->line_edit_font1->text().length() == 7) {

// do something with the valid input

} elseif (ui->line_edit_font1->text().length() == 4) {

// tell user he's bad and he should write only valid things...

}

But how can the user enter invalid short text?
I don't know how this qtvalidator work, but isn't that
enough to prevent the short text?
regards
Nicolai

Apparently it's not enough. I can type in only three letters and move on to next box.

What I want to achieve is that when user has typed in less than seven digits and he jumps to next box, it would revert the box value back to what it was before user started to type the stuff in the box.

That way I could prevent situation where the box has less than seven digits in it.

Berserk 2010-09-30 10:43

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by D-Iivil (Post 829954)
Code:

// tell user he's bad

:D

Quote:

Originally Posted by D-Iivil (Post 829954)
Code:

QRegExp regexer("\\#[0-9a-fA-F]{6,6}");

I think you need to make it this way:
Code:

QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$");
^ = from the start of the string
(.. your characters ..)
$ = until the end of the string

Also, you might consider this:
Code:

ui->line_edit_font1->setValidator(new QRegExpValidator(regexer, ui->line_edit_font1);
I think the parent is wrong, you have it on "this", which is the whole class, I think you need to put it on the QLineEdits specifically.
Edit: this way, you don't have to make "actualvalidator".

d-iivil 2010-09-30 10:43

Re: Need assistance from QT programmer
 
Here's a screenshot of situation I wan't to avoid:
http://i4.aijaa.com/b/00298/6799969.png

d-iivil 2010-09-30 10:49

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Berserk (Post 829981)
:D

I think you need to make it this way:
Code:

QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$");
^ = from the start of the string
(.. your characters ..)
$ = until the end of the string

Also, you might consider this:
Code:

ui->line_edit_font1->setValidator(new QRegExpValidator(regexer, ui->line_edit_font1);
I think the parent is wrong, you have it on "this", which is the whole class, I think you need to put it on the QLineEdits specifically.
Edit: this way, you don't have to make "actualvalidator".

Didn't work. I can still type in only two or three characters and jump on editing next box. However while I do that the signal editingFinished ins't triggered if I don't fill in all seven digits.

So maybe I need to do something with the validator? Tell validator to fill in the previous value if user didn't fill in all required digits? How?

nicolai 2010-09-30 10:58

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Berserk (Post 829981)
:D

I think you need to make it this way:
Code:

QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$");
^ = from the start of the string
(.. your characters ..)
$ = until the end of the string

No. From the Qt-Doc about QtRegExpValidator:
Quote:

... The match is made against the entire string, e.g. if the regexp is [A-Fa-f0-9]+ it will be treated as ^[A-Fa-f0-9]+$.

Diph 2010-09-30 10:58

Re: Need assistance from QT programmer
 
Maybe you can use void QLineEdit::editingFinished () signal.

This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable.

The input is valid if the signal is emitted.

d-iivil 2010-09-30 11:00

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by Diph (Post 829995)
Maybe you can use void QLineEdit::editingFinished () signal.

This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable.

The input is valid if the signal is emitted.

That's the case... signal isn't emitted if I fill in only three digits (or four, or five), but on the screen I see the three digits. I want it to revert back to the value that was in the box before I started editing it and didn't complete the input.

nicolai 2010-09-30 11:04

Re: Need assistance from QT programmer
 
Is the behavrio different, if you use setInputMask instead
of a validator?

http://doc.trolltech.com/4.7/qlineed...inputMask-prop

ui->line_edit_font1->setInputMask("\#NNNNNN");

regards
Nicolai

Diph 2010-09-30 11:07

Re: Need assistance from QT programmer
 
Wild idea. :D

Reimplement void QLineEdit::focusOutEvent ( QFocusEvent * e ) and check what QLineEdit::validator()::validate() returns.

CepiPerez 2010-09-30 11:07

Re: Need assistance from QT programmer
 
So you want to revert to original value in the text lenght is < 7 ?
You can use focusInEvent to save the original text in a qstring and focusOutEvent to revert.

d-iivil 2010-09-30 11:09

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by nicolai (Post 830003)
Is the behavrio different, if you use setInputMask instead
of a validator?

http://doc.trolltech.com/4.7/qlineed...inputMask-prop

ui->line_edit_font1->setInputMask("\#NNNNNN");

regards
Nicolai

Then I can't input anything since it wants me to input all seven digits at the same time (copy paste works, but I can't type the digits one by one).

nicolai 2010-09-30 11:38

Re: Need assistance from QT programmer
 
That is strange, btw my example was wrong. The format
for Hex-Digits is "HHHHHH". I am pretty sure this should work.
But I can not try it out at the moment. Can you try again with the
format:
ui->line_edit_font1->setInputMask("HHHHHH");

d-iivil 2010-09-30 13:08

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by nicolai (Post 830020)
That is strange, btw my example was wrong. The format
for Hex-Digits is "HHHHHH". I am pretty sure this should work.
But I can not try it out at the moment. Can you try again with the
format:
ui->line_edit_font1->setInputMask("HHHHHH");

Thanks! Will test it out tomorrow :) Didn't know there was an input mask for hexes already existing :)

d-iivil 2010-09-30 13:09

Re: Need assistance from QT programmer
 
Quote:

Originally Posted by CepiPerez (Post 830006)
So you want to revert to original value in the text lenght is < 7 ?
You can use focusInEvent to save the original text in a qstring and focusOutEvent to revert.

I can't see such signals in Qt Creator when I right click the lineEdit and select "Go to slot...".

laitiju 2010-09-30 13:24

Re: Need assistance from QT programmer
 
They aren't signals. They are virtual methods. You have to reimplement those methods to use them.

Diph 2010-09-30 13:49

Re: Need assistance from QT programmer
 
I don't know how you can use this in Qt Designer, but you can use those methods like this:

mylineedit.h
PHP Code:

#ifndef MYLINEEDIT_H
#define MYLINEEDIT_H

#include <QLineEdit>

class MyLineEdit : public QLineEdit
{
    
Q_OBJECT
public:
    
MyLineEdit(QWidget *parent 0);

protected:
    
void focusOutEvent(QFocusEvent *event);
    
void focusInEvent(QFocusEvent *event);

};

#endif // MYLINEEDIT_H 

mylineedit.cpp
PHP Code:

#include "mylineedit.h"

MyLineEdit::MyLineEdit(QWidget *parent) :
    
QLineEdit(parent)
{
}

void MyLineEdit::focusInEvent(QFocusEvent *event)
{
    
//Save text from line edit
}

void MyLineEdit::focusOutEvent(QFocusEvent *event)
{
    
//Restore text if it is not valid



Berserk 2010-10-01 22:14

Re: Need assistance from QT programmer
 
Sorry for changing the subject, but the GConfItem problem still remains for both D-Livil and me..



Quote:

Originally Posted by Diph (Post 826131)
Install lib in scratchbox armel target and make links of gconf lib and include files under usr and place them in NokiaQtSDK Maemo usr/lib and usr/include.

I use WinXP, and I'm afraid I can't install libs using Madde, or is it possible?

I've downloaded libgq-gconf-dev_0.2-3+0m5_armel.deb from the package page,
Then I unpacked everything into:
E:\NokiaQtSDK\Maemo\4.6.2\sysroots\fremantle-arm-sysroot-1030-slim\usr
and added your suggestion to src.pro:
Quote:

Originally Posted by Diph (Post 826077)
Code:

CONFIG += link_pkgconfig
PKGCONFIG += gq-gconf


But I still can't include GConfItem..
Copying doesn't seem like the right way to do it, but I'm clueless.

==================================================

I did manage to include GConfItem by putting these files in my project, but those files also had their own includes, and it seemed endless to me.
It wouldn't build because I don't have those headers.

Another thing.. I see "#include <gconf/gconf.h>" here and there, but in my setup it's "#include <gconf/2/gconf/gconf.h>". I didn't change anything manually, just a straightforward Nokia Qt SDK install.
The #include lines in those headers point to <gconf/....h>, so that's a dead end.


I hope I don't bother anyone too much about this, but any help would be great

Berserk 2010-10-02 00:24

Re: Need assistance from QT programmer
 
Well.. I think it's solved :D

Use system("command");
But be careful with system commands :D

For instance, when you use
Code:

system("gconftool-2 -R /apps/osso/hildon-desktop/views");
It outputs this:
Code:

current = 1
 active = [1,2,3,4]
 /apps/osso/hildon-desktop/views/1:
  bg-image = /home/user/MyDocs/.images/abstract1_01.jpg
 /apps/osso/hildon-desktop/views/2:
  bg-image = /home/user/MyDocs/.images/abstract1_02.jpg
 /apps/osso/hildon-desktop/views/3:
  bg-image = /home/user/MyDocs/.images/abstract1_03.jpg
 /apps/osso/hildon-desktop/views/4:
  bg-image = /home/user/MyDocs/.images/abstract1_04.jpg

I'll write how to catch that output in a QString tomorrow, time for some sleep first..


I've been able to set backgrounds with the following:
Code:

system('gconftool -s /apps/osso/hildon-desktop/views/1/bg-image -t string "/home/user/MyDocs/.images/abstract1_01.jpg"');
(For every desktop)


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

vBulletin® Version 3.8.8