View Single Post
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: