Check that your connections aren’t affected by disconnect statements.ġ5. Not _myObj = new M圜lass() _myObj-> init() ġ4. Put all connect statements before functions calls that may fire their signals, to ensure that the connections are made before the signals are fired. For example: _myObj = new M圜lass() Ĭonnect( _myObj, SIGNAL( somethingHappend()), SLOT( doSomething())) Use break points or qDebug to check that slots are being called the appropriate number of times: make sure the connection isn’t made repeatedly.ġ3. Make sure to run qmake after adding the Q_OBJECT macro to a class. Check that classes using signals and slots inherit QObject or a QObject subclass.ġ1. Make sure the Q_OBJECT macro is inserted at the beginning of your class declaration.ġ0. Now you are ready to start developing your own applications. If you have not done so before, go to Building and Running an Example. To check that kits for building and running were successfully installed as part of the Qt installation, open an example application and run it. If you use custom signals, check that these are declared correctly, with a void return type, in the public/protected/private signals section of your class declaration.ĩ. For an overview of the options you have, go to Configuring Qt Creator. Check that you’ve used private slots:, for example not slots. Check that slots are declared correctly in the appropriate public/protected/private slots sections of your class declaration.
You can do this with code like the following:Ĭonnect(this, SIGNAL(mySignal()), qApp, SLOT(aboutQt())) ħ. Check that the signal is being fired as expected. The connect statement should look like this:Ĭonnect(senderObject, SIGNAL(mySignal(const QString&)), receiverObject, SLOT(mySlot(const QString&))) Ĭheck brackets, check that SIGNAL and SLOT are capitalised and that the sender and receiver are both objects, not class names.Ħ. Check that the connect argument types and syntax are correct. Make sure you haven’t added a name to the signal or slot argument: for example, use textChanged(const QString &) not textChanged(const QString &text).ĥ. Thanks to the unified Qt installer, the process is very similar to that on Windows and Linux, so well just cover some of the differences and highlights of the Mac install. Lets look at installation on the remaining major desktop platform, macOS.
Check that the parameter types of the signal and slot are exactly correct and, as appropriate, that they match.Ĥ. Two earlier blog posts (1) (2) covered how to set up Qt and Qt Creator on Windows and Linux systems. Use break points or qDebug to check that signal and slot code is definitely reached:ģ. Check for compiler warnings about non-existent signals and/or slots.Ģ. Below are some suggestions for troubleshooting signals and slots in the Qt C++ library.ġ.