Jump to content

Qt Demo Script

From Qt Wiki
Revision as of 07:49, 24 February 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

<br />#include &lt;QtCore&amp;gt;

int main(int argc, char **argv)<br />{<br /> // sample code goes here<br />}<br />

Fun with Strings


QString s1("Hello&quot;);
QString s2("World&quot;);
QString s = s1 + " " + s2;
qDebug() << s; // "Hello World&quot;

This is easy.

List of Strings


QList&lt;QString&gt; list;
list << s1 << s2;
qDebug() << list;
// or
list = s.split(" "); // "Hello World&quot; => ["Hello&quot;, "World&quot;]

QStringList


QString s("Hello World&quot;);
QStringList list = s.split(" ");
QString s2 = list.join(" ") + "!";
QDebug() << s << " => " << list; << " => " << s2; // "Hello World => ["Hello&quot;, "World&quot;] => "Hello World!"