Qt for Visual Studio Add-In can not connect signals to slots that depend on conditional compilation

  • It looks logical that application debug version uses more signals and slots to monitor application execution than release one. Application may also have different debug modes that give more attention to specific problems.
    I have such application that I compile with Visual Studio. I have signal that I want to use when some debug mode is enabled. I use preprocessor definition, lets say, DEBUG_MODE_1. I create slot in following way:

    #ifdef DEBUG_MODE_1
    private slots:
       void MyDebugSlot(void);

    I use Visual Studio project settings to add DEBUG_MODE_1 preprocessor definition when I compile in some debug configuration. The problem is that when I use connect with MyDebugSlot, I receive following error message: QObject::connect: No such slot

    It however connects successfuly when I comment #ifdef statement.
    So, it looks like Qt for Visual Studio Add-In ignores project preprocessor definition, and as a result I have to remove #ifdef and include a lot of not needed debugging functionality in release, or I have to modify source code manually between release and debug builds.
    Is there any way to make Qt slots dependent on preprocessor definitions in Visual Studio?

  • Moderators

    Hi, welcome to devnet.

    As far as I can tell the scenario you described works correctly. The add-in passes the project defines to moc and it generates or not the slot metadata, depending on the define.

    Make sure you define the symbol in Project Properites -> C/C++ -> Preprocessor -> Preprocessor Definitions. The add-in will not pick it up otherwise e.g. if you define it in some include file or manually via /D switch to the compiler.

    Also, which Qt/add-in version are you using? Some very old moc versions did not handle preprocessor correctly.

  • Hi, thansk for your reply. I use Visual Studio 2013 and Qt Visual Studio Add-In 1.2.4. Qt version is Qt 5.5.1 MSVC2013 64bit (one I downloaded with Qt Maintenance tool). I define preprocessor at preprocessor definitions for Debug configuration. Visual Studio intellisence recognizes it, and project compiles successfuly.
    May be I have to force Visual Studio to re-run moc somehow if it is not done automatically during build process?

  • Moderators

    The moc is re-run whenever a change in the header occurs. You can clean the project and rebuild but I doubt it will change anything.
    Can you inspect the generate moc_* files to see if your slot is there for the release and debug builds?

  • Well, I was able to force it to work by removing Q_OBJECT, rebuild and adding Q_OBJECT back. So, it looks like Qt for Visual Studio Add-In doesn't update Generated Files correctly.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.