PDA

View Full Version : A collection of letters and numbers



NewLegend
8th September 2010, 18:01
Hello

I want to print a set of numbers and letters.
How can I do that, I want a simple example.

tbscope
8th September 2010, 18:19
Use any of the print or output stream functions.

Google for printf or cout, or check the qt docs for qdebug or qtextstream(stdout)

NewLegend
8th September 2010, 18:33
Use any of the print or output stream functions.

Google for printf or cout, or check the qt docs for qdebug or qtextstream(stdout)

I using Qt Creator

tbscope
8th September 2010, 18:38
Do you have a specific question?

This is basic C++ and hasn't anything to do with Qt.

Here's an example, and I'm being very very generous here.


#include <stdio.h>

int main(int argc, char *argv[])
{
printf("Hello world!\n");

return 0;
}

NewLegend
8th September 2010, 19:18
But I want to print numbers and letters inside the For loop
Like,

void MainWindow :: print()
{
int x;
for(int i=0; i<100 ; i++)
{
// <-- Here's what I put to print the " Number = x"
x++;
}

}


as
http://www.forum.nokia.com/piazza/wiki/images/9/9a/QtS60AppForm.jpg?20081231123546

tbscope
8th September 2010, 19:27
Do you want to display the text in a text editor or a label?

If so, use something like:


QString("Number = %1").arg(x);
Use the setText or setPlainText function of the text edit or label

Zlatomir
8th September 2010, 19:28
void MainWindow :: print()
{
int x;
for(int i=0; i<100 ; i++)
{
// <-- Here you can use the print just like outside of for
cout << x << ' '; //print with a space between
//or
qDebug() << 100; //
//or even printf
x++;
}

}


Just make sure that you include the necessary header file.

And don't forget to initialize x

Zlatomir
8th September 2010, 19:38
Sorry i skipped the picture in the first place

To replicate the interface within that picture you will need to use widgets and layouts
Like QLabel to just display some text, or QSpinBox to display a spinbox where the user can select a value
And there are some QPushButton, QLineEdit and a QTextEdit

LE: link to tutorials (http://doc.qt.nokia.com/4.6/tutorials.html) that should give you an easier start with Qt, if you don't understand something you can ask more specific questions on the forum ;)

NewLegend
8th September 2010, 19:44
Now used textBrowser
But it takes a lot of time for the exit of the results

void MainWindow :: print()
{

for(int i=0; i<200 ; i++)
{
ui->textBrowser->setPlainText(ui->textBrowser->toPlainText() + "Hiiiii " + "\n" );

}

}