Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [Moved] MOC doesn’t preprocess C/C++ Macros. Any way around that?

    Tools
    3
    3
    2104
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      ronM71 last edited by

      I want to write a Macro that would define a collection of slots and signals, to make it easier for developers. I can't see how I'm using base class for this as not all classes who'd benefit from that Macro (present and future) derive from one class I have control over.

      so I defined a sample macro with one slot and one signal. If I use the same "string" in my class definition, it works. if I use the "macro" in my class, my build fails link. I was told it's because the MOC doesn't pre-process the C++ macro.

      Any way around that?

      1 Reply Last reply Reply Quote 0
      • G
        giesbert last edited by

        moc does not do pre processing, it just parses your source (or usually the header) for some keywords and builds up information based on this. If you want to do pre processing, you have to change the build chain with qmake, as you the would need some pre processing --> create püre_header and use pre_header for moc. This is afaik not possible with qmake and default Qt :-( We also had an idea for such things, and went back to the usual way, even if it is more work.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply Reply Quote 0
        • F
          florent.revelut last edited by

          We had a similar issue with templates, which are somehow C++ macros (just better or worse, depending if you write them or have to understand the ones of another developper....)

          One of the solution we had was to define virtual interface for our slots, and then, have our real class derivate from interface and qobject, just redefining the previous virtual functions as slots.

          The fun thing is you can do the connect from your interface as it's done on runtime. Kind of risky however to maintain, so we finished by generating these aprts of code with some external python scripting.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post