Qt Demo Script

From Qt Wiki
Revision as of 16:45, 3 March 2015 by AutoSpider (talk | contribs) (Add "cleanup" tag)
Jump to navigation Jump to search
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

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