Elementolab/QT Tips

From Icbwiki

Jump to: navigation, search
  • (For Mac) How to auto complete your code (names of variables/functions)
Ctrl+Space
  • Easy way to run a function from a separate thread
extern void aFunction();
QFuture<void> future = QtConcurrent::run(aFunction);

More details: http://doc.qt.nokia.com/4.6/qtconcurrentrun.html#run
  • How to make a QWidget non-resizable. Add in its constructor:
this->setFixedSize(size());
  • How to print a QString
QString yourString = ...
cout<<QPrintable(yourString)

or:

cout << yourString.toStdString()     # convert to an STL string
  • How to convert int to QString
QString::number(yourInteger)
  • How to substring a QString
QString tmp = "myString";
QString l   = tmp.left(2)   // my
QString r   = tmp.right(3)  // String
QString m   = tmp.mid(3,2)  // Str
Personal tools