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)
Jump to navigation Jump to search

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

<br />QString s1(&quot;Hello&amp;quot;);<br />QString s2(&quot;World&amp;quot;);<br />QString s = s1 + &quot; &quot; + s2;<br />qDebug() &lt;&lt; s; // &quot;Hello World&amp;quot;<br />

This is easy.

List of Strings

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

QStringList

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