Qt Demo Script

From Qt Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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!"