Common problems
From qtnode
Contents |
Problems Using Qt
MSYS, sh.exe, and backslashes
Problem: You get errors like /bin/sh.exe: C:Qt4.0.1binmoc.exe: command not found
Solution: MSYS backslash problems
Unable to see output on the console
Problem: Your qDebug() don't display anything on the console, neither does cout or printf
Solution 1: Enable console output
Solution 2 (Windows): Watch debug output using DebugView. This does not include output done via cout or printf.
My signals/slots don't report errors on connection
Problem: Your connection code is getting executed, but the associated slot does not run when its signal is emitted
Solution: Enable console output, Enable debug
Linker Errors When Trying to set the Application Icon
Problem: You're using MinGW and get linker errors when following the instructions for Setting the Application Icon.
Solution: Make sure your Windows resource (.rc) files have different base names than your source files. If using MinGW be aware that the windres program compiles .rc files as .o files. So if you have myapp.cpp and myapp.rc, then they will both be compiled as myapp.o. Visual C++ doesn't have this problem, since the rc program will output a .res file instead.
Trolltech has posted a task tracker for this issue. Please visit the task tracker website for more information.
"Cannot queue arguments of type..." error
Problem: When connecting a signal to a slot that needs to be queued, you receive a runtime error message: QObject::connect: Cannot queue arguments of type 'someObjecType'
Solution: Register a named type in the meta object system
`vtable` Undefined
Problem: Linking produces errors like Undefined reference to `vtable for 'MyClass'.
Solution: `vtable` is part of the object metadata structure. Its definition is generated by moc, so these errors indicate moc is not getting successfully run on your class.
- Make sure you have the Q_OBJECT macro only in your header files, once in each QObject-derived class.
- Make sure all your header files are listed in your .pro in the HEADERS= list, or run qmake -project to regenerate your .pro file automatically.
- Re-run qmake every time you add Q_OBJECT to one of your classes.
- If your class is all in one file, ie the class MyClass {...} along with the implementation, then you need to include the generated moc file in the file where the class is. A better solution is to always keep a separate header file for the class definition.
When should I delete my objects?
Problem: Different objects have different lifespans and you don't know when to delete them.
Solution: Follow these rules of thumb.
- If the class does not inherit QObject, and you instantiated it using operator new, you must delete it using operator delete.
- If the class inherits QObject, and you instantiated it on the stack (that is, without using operator new), be sure that you do not provide a parent object. The object will be automatically deleted when the function ends.
- If the class inherits QObject, and you instantiated it using operator new, be sure to provide a parent QObject when you create it. Qt will automatically destroy this object when the parent is deleted.
- If you must delete a parented QObject before its parent, strongly consider using QObject::deleteLater(), especially if you perform this delete inside a slot or event handler.
Problems Compiling/Installing Qt
QtValidLicenseForGuiModel error
Problem: you get an error that says something like: error: `QtValidLicenseForGuiModule' does not name a type
Solution: QtValidLicenseForGuiModule error
Building Qt with MySql support
Problem: How do I configure where mysql includes are? (we get this one alot)
Solution: Sometimes (often) you may find that your mysql includes and libs are not where Qt normally expects them to be. To change the default configuration execute the following commands in the Qt source directory at the bash prompt:
./gmake confclean ./configure -qt-sql-mysql -lmysql -I/usr/include/mysql -L/usr/lib/mysql
(obviously replace /usr/include/mysql and /usr/lib/mysql with your correct Include and Lib paths - see Qt4 on Windows for more info)
Building Qt4.1.1 with Sound support
Problem: You cannot compile Qt4.1.1 if it has been configured with both --system-nas-sound and --no-qt3support.
Solution: You need Qt3Support. Remove the --no-qt3support from the ./configure command, run make confclean and re ./configure. (This has been fixed for future releases > 4.1.2)