maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   I'm learning with Qt and I have a question (https://talk.maemo.org/showthread.php?t=47962)

krk969 2010-03-22 15:01

Re: I'm learning with Qt and I have a question
 
Quote:

Originally Posted by tdesws (Post 577137)
erm.. how do I do that?

mainwindow.h
Code:

class MainWindow
{
........

private:
        static int  _clickCounter;
};

mainwindow.cpp
in the first line of the file just after all the #includes define this variable,
Code:

int MainWindow::_clickCounter = 0;
and modfiy your slot with something like this
Code:

void MainWindow::on_Button_clicked()
{
      ui->label->setText(QString("this is text %1").arg(QString::number(++_clickCounter) );
}


krk969 2010-03-22 15:05

Re: I'm learning with Qt and I have a question
 
Quote:

Originally Posted by gabby131 (Post 577146)
this is telling me that QT is like a Programming language or something to do with code, strings and etc....

QT is mainly a graphical toolkit that will allow you to create cross platform code with graphical interfaces, you can use it for backend server coding also, if you like :D
QT is based on C++, so if you know C++ ( even some basics ), you should feel at home.

tdesws 2010-03-22 17:57

Re: I'm learning with Qt and I have a question
 
Quote:

Originally Posted by krk969 (Post 577230)
mainwindow.h
Code:

class MainWindow
{
........

private:
        static int  _clickCounter;
};

mainwindow.cpp
in the first line of the file just after all the #includes define this variable,
Code:

int MainWindow::_clickCounter = 0;
and modfiy your slot with something like this
Code:

void MainWindow::on_Button_clicked()
{
      ui->label->setText(QString("this is text %1").arg(QString::number(++_clickCounter) );
}


I've made it to work, but i meant that later it wont be just +1 it will be something like: Hello changes to Mouse and then word mouse changes to some other word or sentence

krk969 2010-03-22 17:58

Re: I'm learning with Qt and I have a question
 
so you want to print a random text from a list every time you click ?
whats the requirement ?

tdesws 2010-03-22 18:08

Re: I'm learning with Qt and I have a question
 
Quote:

Originally Posted by krk969 (Post 577535)
so you want to print a random text from a list every time you click ?
whats the requirement ?

Well I have like 500 lines of text
something like this:
1. Hello
2. Meow
3. Lol
......
500. Text

and i want it to show next line everytime i press next

krk969 2010-03-22 18:21

Re: I'm learning with Qt and I have a question
 
Quote:

Originally Posted by tdesws (Post 577564)
Well I have like 500 lines of text
and i want it to show next line everytime i press next

put all your words in a file(example /home/user/wordlist) , 1 word per line.

mainwindow.h
Code:

class MainWindow
{
...
private:  // member functions
        void MainWindow::initMyWordList();
private: // member variables
        static int  _clickCounter;
        QStringList _wordList;
};

mainwindow.cpp
Code:

in the first line of the file just after all the #includes define this variable,

int MainWindow::_clickCounter = 0;

and in

MainWindow()
{
....
error = initMyWordList();
if ( error )
  do whatever you feel like
....
}

//init my word file
void MainWindow::initMyWordList()
{
        QFile * wordFile = new QFile("/home/user/wordlist");
        wordFile->open(QIODevice::ReadOnly);

        QTextStream stream(wordFile);

        // create the map of channel and date until which data is available
        while ( !stream.atEnd() )
        {
                QString word = stream.readLine();
                _wordList << word;
        }

        wordFile->close();
}

void MainWindow::on_Button_clicked()
{
      ui->label->setText(QString("the word of the day is %1").arg(_wordList[_clickCounter++]) );
}


tdesws 2010-03-24 13:44

Re: I'm learning with Qt and I have a question
 
Here's my window.h
Code:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void buttonClickHandler();

protected:
    void changeEvent(QEvent *e);

private:
    Ui::MainWindow *ui;
    {
    private:  // member functions
            void MainWindow::initMyWordList()
    private: // member variables
            static int  _clickCounter;
            QStringList _wordList;
    };
private slots:

private slots:
    void on_Button_clicked();
};


#endif // MAINWINDOW_H

and mainwindow.cpp
Code:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
int MainWindow::_clickCounter = 0;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::buttonClickHandler()
{
}

void MainWindow::on_Button_clicked()
{
....
error = initMyWordList();
if ( error )
  do whatever you feel like
....
}

//init my word file
void MainWindow::initMyWordList()
{
        QFile * wordFile = new QFile("/home/user/wordlist");
        wordFile->open(QIODevice::ReadOnly);

        QTextStream stream(wordFile);

        // create the map of channel and date until which data is available
        while ( !stream.atEnd() )
        {
                QString word = stream.readLine();
                _wordList << word;
        }

        wordFile->close();
}

void MainWindow::on_Button_clicked()
{
      ui->label->setText(QString("the word of the day is %1").arg(_wordList[_clickCounter++]) );
}

but when i try to build i get: C:/Users/Edvinas/Documents/InteractiveHelloWorld/mainwindow.h:24: error: expected unqualified-id before '{' token

VDVsx 2010-03-24 14:13

Re: I'm learning with Qt and I have a question
 
Removes the brackets in line 24 and 30.

krk969 2010-03-24 14:14

Re: I'm learning with Qt and I have a question
 
Quote:

Originally Posted by tdesws (Post 580293)
Here's my window.h
Code:

....
private:
    Ui::MainWindow *ui;
    {
    private:  // member functions
            void MainWindow::initMyWordList()
    private: // member variables
            static int  _clickCounter;
            QStringList _wordList;
    };

but when i try to build i get: C:/Users/Edvinas/Documents/InteractiveHelloWorld/mainwindow.h:24: error: expected unqualified-id before '{' token

change the above to
....
private:
Ui::MainWindow *ui;
// member functions
void MainWindow::initMyWordList()
// member variables
static int _clickCounter;
QStringList _wordList;
};
....

tdesws 2010-03-24 14:52

Re: I'm learning with Qt and I have a question
 
now it looks like that:

mainwindow.h:
Code:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void buttonClickHandler();

protected:
    void changeEvent(QEvent *e);

private:

    {
    Ui::MainWindow *ui;
    // member functions
    void MainWindow::initMyWordList();
    // member variables
    static int _clickCounter;
    QStringList _wordList;
    }

//private slots:
    //void on_Button_clicked();


#endif // MAINWINDOW_H

main.cpp:
Code:

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}
}

mainwindows.cpp:
Code:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
int MainWindow::_clickCounter = 0;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::buttonClickHandler()
{
}

void MainWindow::on_Button_clicked()
{
error = initMyWordList();
if ( error )
  do whatever you feel like
}

//init my word file
void MainWindow::initMyWordList()
{
        QFile * wordFile = new QFile("C:\Users\Edvinas\Desktop\MAEMO\N900\Development\test");
        wordFile->open(QIODevice::ReadOnly);

        QTextStream stream(wordFile);

        // create the map of channel and date until which data is available
        while ( !stream.atEnd() )
        {
                QString word = stream.readLine();
                _wordList << word;
        }

        wordFile->close();
}

void MainWindow::on_Button_clicked()
{
      ui->label->setText(QString("the word of the day is %1").arg(_wordList[_clickCounter++]) );
}

And i get:

C:/Users/Edvinas/Documents/InteractiveHelloWorld/main.cpp:2: In file included from main.cpp:2:

C:/Users/Edvinas/Documents/InteractiveHelloWorld/mainwindow.h:24: error: expected unqualified-id before '{' token

C:/Users/Edvinas/Documents/InteractiveHelloWorld/main.cpp:10: error: expected unqualified-id at end of input


All times are GMT. The time now is 14:58.

vBulletin® Version 3.8.8