User Tools

Site Tools


info:qt

Qt

Pros

  • Set of libraries similar in scope to Java
  • Qt Designer GUI builder
  • Better platform integration than Java
  • Advantages of C++

Cons

  • Uses old-style check-return-value-for-every-function error handling instead of exceptions
  • In cases where documentation is not very good or very complete (e.g. for qmake, or the Q_ENUMS macro), it can be hard to find good information (probably due to a smaller community of Qt users compared to Java)
  • Fairly large libraries required to run (but smaller than Java)
  • Disadvantages of C++ (e.g. less static checking, worse IDE support)

General Notes

Number of Copies of Arguments for Signal-Slot Connections

From http://www.embeddeduse.com/2013/06/29/copied-or-not-copied-arguments-signals-slots/

Conclusion: use const references whenever possible to minimize copying; for direct connections, this results in no copying. Queued connections add 1 extra copy over direct connections.

Here is a copy of the table from the article:

Signal Slot Direct Queued
const Copy& const Copy& 0 1
const Copy& Copy 1 2
Copy const Copy& 1 2
Copy Copy 2 3

Qt Database Applications

See some old notes here: Qt Database Application.

Use the qPrintable macro when you need to print/stream QStrings:

std::cout << qPrintable(QString("foo")) << std::endl;

This is equivalent to QString("foo").toLocal8Bit().constData().

Qt 5 Notes

Qt Libraries

Troubleshooting

Linker vtable Error

I've experienced this with Qt 3, so I'm not sure if the same thing happens with Qt 4.

This appears on an object inheriting QObject (maybe indirectly) and defining the Q_OBJECT macro. The errors look like this:

build/TrendCfgTrace.o: In function `TrendCfgTrace':
/home/samh/projects/gtrend/trendconfig/TrendCfgTrace.cpp:12: undefined reference to `vtable for TrendCfgTrace'
/home/samh/projects/gtrend/trendconfig/TrendCfgTrace.cpp:12: undefined reference to `vtable for TrendCfgTrace'
build/TrendCfgTrace.o: In function `~TrendCfgTrace':
/home/samh/projects/gtrend/trendconfig/TrendCfgTrace.cpp:16: undefined reference to `vtable for TrendCfgTrace'
/home/samh/projects/gtrend/trendconfig/TrendCfgTrace.cpp:16: undefined reference to `vtable for TrendCfgTrace'
/home/samh/projects/gtrend/trendconfig/TrendCfgTrace.cpp:16: undefined reference to `vtable for TrendCfgTrace'

Apparently the solution is to re-run qmake on the file, and then rebuild. See http://lists.trolltech.com/qt-interest/2007-10/thread00077-0.html.

Qt 3 and Qt 4 coexisting

If you call qmake-qt4 with the -qt4, it will put that exact name in the makefiles it generates for the QMAKE variable. qmake-qt3 doesn't appear to be as smart. For now, I've changed the alternative (using G Alternatives, though the command-line tool would work just as well) to qmake-qt3. Qt 4 programs seem to be perfectly happy about this.

No matching function for call to connect to pointer reference (possibly in a subclass of a Qt Designer-generated class)

I've experienced this with Qt 3, so I'm not sure if the same thing happens with Qt 4.

For instance, if this:

connect(buttonOk, SIGNAL(clicked()), this, SLOT(saveCfgObject()));

produces this error:

cfgrootdlg.cpp: In constructor ‘CfgRootDlg::CfgRootDlg(TrendCfgRoot&, QWidget*, const char*)’:
cfgrootdlg.cpp:46: error: no matching function for call to ‘CfgRootDlg::connect(QPushButton*&, const char [11], CfgRootDlg* const, const char [17])’
/usr/include/qt3/qobject.h:119: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*)
/usr/include/qt3/qobject.h:229: note:                 bool QObject::connect(const QObject*, const char*, const char*) const

The problem in this case seems to be that the class QPushButton had a forward declaration in CfgRootDlg's parent class. Including qpushbutton.h eliminated the problem. I found the suggestion here: http://www.qtcentre.org/forum/f-newbie-4/t-integrating-qt3-designer-with-code-based-application-7714.html.

info/qt.txt · Last modified: 2014-06-13 22:44 by sam