views:

1400

answers:

6

A little is hidden in Qt given splendid documentation. But given vastness of Qt functionality paradoxically many useful features have been overlooked by me (and reimplemented or work-arounded).

What Qt functions you wish you have noticed earlier?

+8  A: 

One feature I found too late was stdin-stout handling through QFile. I could drop then all std::*.

Other was (not easy to find in documetation):

qDebug () << x;

Which proved very convenient for debugging.

Recently I found easy serialization class QDataStream.

Łukasz Lew
+13  A: 
  • qPrintable( string ) is easier to remember and quicker to type than string..toLocal8Bit().constData().
  • QSignalMapper for funneling a lot of signals into one slot with an index.
  • Qt's various smart pointers, expecially QPointer
  • A large number of various qmake tips and tricks, many of which originated from undocumented qmake and similar pages.

I'm sure I'll think of more later, as well.

Caleb Huitt - cjhuitt
+1 for qPrintable()
Graphics Noob
The "undocumented qmake" is a GREAT resource.
Detro
+13  A: 
  1. Using QObject::find_children<>() to expose hidden childs
  2. Using qobject_cast() to for proper inheritance
  3. Abusing QMetaOject (I assume I will need it some day)
  4. QObject::deleteLater() -> delete(this) !!!
  5. QObject::EventFilter()
  6. Even though qmake is really a toy, it can be used for compiling with other frameworks (I did a pure OpenGL application, and for the build system I used qmake-qt3. I once even compiled a GTK application using QMake.
  7. Qt has a YouTube channel, you can find cool things there
elcuco
After some tests I've found that qobject_cast() is actually quite a lot faster than dynamic_cast()
frgtn
+17  A: 

Here's a list that I blogged recently:

  • Q_GADGET offers some meta-object features without the need to inherit QObject. Combined with Q_ENUMS it allows reflection for enums.
  • You can declare a single signal or slot by using the Q_SIGNAL and Q_SLOT macros.
  • Q_FOREACH and Q_FOREVER
  • qChecksum offers a CRC implementation
  • qCompress / qUncompress
  • Use qDeleteAll to delete each element in a container
  • Use qRound for float to integer rounding
  • qFuzzyCompare: safe compare for float and double values
  • qVersion: Get the runtime qt lib version
  • Use sender() to get the emitter of the current slot. Only works for direct connections.
  • QSysInfo header: word size, endianness, OS version
  • QtEndian header
rpg
+1 NICE, just NICE
elcuco
+1. Great list.
Rob
+5  A: 
  • CONFIG += silent for qmake project files. Hides full compiler output unless there's a warning or error.
frgtn
+4  A: 

You can connect signals to signals in order to emit a signal automatically. This is useful to provide signals from underlying classes. QTabWidget uses a QTabBar and exposes the signals from the QTabBar using a trick like this:

connect(myObj, SIGNAL(internalSignal(int)), SIGNAL(externalSignal(int)));

Which will make the current class emit externalSignal(int) when myObj emits internalSignal(int). This helps with the signal side of things at least. There is no equivalent way to do this with slots that I know of; the only simple way is to make your externalSlot call internalSlot.

Source: http://goo.gl/laiU

iconiK