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

  1. #include <QtCore>
  2.  
  3. int main(int argc, char **argv)
  4. {
  5.   // sample code goes here
  6. }

Fun with Strings

  1. QString s1("Hello");
  2. QString s2("World");
  3. QString s = s1 + " " + s2;
  4. qDebug() << s; // "Hello World"

This is easy.

List of Strings

  1. QList<QString> list;
  2. list << s1 << s2;
  3. qDebug() << list;
  4. // or
  5. list = s.split(" "); // "Hello World" => ["Hello", "World"]

QStringList

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