Qt Demo Script: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
= Main function = | = Main function = | ||
<code> | <code> | ||
#include <QtCore> | |||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||
{ | |||
// sample code goes here | |||
} | |||
</code> | |||
= Fun with Strings = | = Fun with Strings = | ||
<code> | <code> | ||
QString s1("Hello"); | |||
QString s2("World"); | |||
QString s = s1 + " " + s2; | |||
qDebug() << s; // "Hello World" | |||
</code> | |||
This is easy. | This is easy. | ||
Line 17: | Line 27: | ||
= List of Strings = | = List of Strings = | ||
<code>< | <code> | ||
QList<QString> list; | |||
list << s1 << s2; | |||
qDebug() << list; | |||
// or | |||
list = s.split(" "); // "Hello World" => ["Hello", "World"] | |||
</code> | |||
= QStringList = | = QStringList = | ||
<code> | <code> | ||
QString s("Hello World"); | |||
QStringList list = s.split(" "); | |||
QString s2 = list.join(" ") + "!"; | |||
QDebug() << s << " => " << list; << " => " << s2; // "Hello World => ["Hello", "World"] => "Hello World!" | |||
</code> |
Revision as of 13:32, 25 February 2015
This is a short introduction to Qt using a simple demo script. We play around with strings and look into the issue how to present them.
Let's get started.
Main function
#include <QtCore>
int main(int argc, char **argv)
{
// sample code goes here
}
Fun with Strings
QString s1("Hello");
QString s2("World");
QString s = s1 + " " + s2;
qDebug() << s; // "Hello World"
This is easy.
List of Strings
QList<QString> list;
list << s1 << s2;
qDebug() << list;
// or
list = s.split(" "); // "Hello World" => ["Hello", "World"]
QStringList
QString s("Hello World");
QStringList list = s.split(" ");
QString s2 = list.join(" ") + "!";
QDebug() << s << " => " << list; << " => " << s2; // "Hello World => ["Hello", "World"] => "Hello World!"