Reply
Thread Tools
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#11
Originally Posted by tdesws View Post
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) );
}
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 

The Following User Says Thank You to krk969 For This Useful Post:
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#12
Originally Posted by gabby131 View Post
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
QT is based on C++, so if you know C++ ( even some basics ), you should feel at home.
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 

The Following 2 Users Say Thank You to krk969 For This Useful Post:
Posts: 23 | Thanked: 0 times | Joined on Dec 2009
#13
Originally Posted by krk969 View Post
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's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#14
so you want to print a random text from a list every time you click ?
whats the requirement ?
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 

The Following User Says Thank You to krk969 For This Useful Post:
Posts: 23 | Thanked: 0 times | Joined on Dec 2009
#15
Originally Posted by krk969 View Post
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's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#16
Originally Posted by tdesws View Post
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++]) );
}
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”

Last edited by krk969; 2010-03-22 at 18:27.
 

The Following 2 Users Say Thank You to krk969 For This Useful Post:
Posts: 23 | Thanked: 0 times | Joined on Dec 2009
#17
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's Avatar
Posts: 1,070 | Thanked: 1,604 times | Joined on Sep 2008 @ Helsinki
#18
Removes the brackets in line 24 and 30.
__________________
Valério Valério
www.valeriovalerio.org
 

The Following User Says Thank You to VDVsx For This Useful Post:
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#19
Originally Posted by tdesws View Post
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;
};
....
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 

The Following User Says Thank You to krk969 For This Useful Post:
Posts: 23 | Thanked: 0 times | Joined on Dec 2009
#20
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
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 09:31.