Hello
I want to print a set of numbers and letters.
How can I do that, I want a simple example.
Hello
I want to print a set of numbers and letters.
How can I do that, I want a simple example.
Use any of the print or output stream functions.
Google for printf or cout, or check the qt docs for qdebug or qtextstream(stdout)
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.
Qt Code:
#include <stdio.h> int main(int argc, char *argv[]) { printf("Hello world!\n"); return 0; }To copy to clipboard, switch view to plain text mode
But I want to print numbers and letters inside the For loop
Like,
Qt Code:
void MainWindow :: print() { int x; for(int i=0; i<100 ; i++) { // <-- Here's what I put to print the " Number = x" x++; } }To copy to clipboard, switch view to plain text mode
as
Last edited by NewLegend; 8th September 2010 at 19:22.
Do you want to display the text in a text editor or a label?
If so, use something like:
Use the setText or setPlainText function of the text edit or labelQt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
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++; } }To copy to clipboard, switch view to plain text mode
Just make sure that you include the necessary header file.
And don't forget to initialize x
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 that should give you an easier start with Qt, if you don't understand something you can ask more specific questions on the forum
Last edited by Zlatomir; 8th September 2010 at 19:46. Reason: added a link to Qt tutorials
Now used textBrowser
But it takes a lot of time for the exit of the results
Qt Code:
void MainWindow :: print() { for(int i=0; i<200 ; i++) { ui->textBrowser->setPlainText(ui->textBrowser->toPlainText() + "Hiiiii " + "\n" ); } }To copy to clipboard, switch view to plain text mode
Bookmarks