Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:01:03+00:00 2026-05-30T14:01:03+00:00

In an effort to optimize the binary of a Qt-based dynamic library, I’m attempting

  • 0

In an effort to optimize the binary of a Qt-based dynamic library, I’m attempting to selectively export a number of relevant methods from classes that inherit from QObject and use moc to define custom signals and slots, instead of exporting them entirely (all of their members). Some sample code is below.

#ifdef LIB_BUILD
    #define LIB_SHARED Q_DECL_EXPORT
#else
    #define LIB_SHARED Q_DECL_IMPORT
#endif

class C: public QObject {
    Q_OBJECT

public:
    LIB_SHARED void f();
    /* ... */

public slots:
    LIB_SHARED void g();

private:
    void h();

private slots:
    void i();
};

The idea: since h() and i() are private (and no inline method call any of these functions), there is no need to export these symbols, since they will be used by the library alone. On the other hand, f() and g() are members eligible for exporting, so they’re explicitly marked for that.

The problem: the Q_OBJECT macro declares a couple of virtual method overrides for methods in QObject, and these methods are not exported (since the macro will expand to declarations not containing LIB_SHARED or Q_DECL_EXPORT). Thus, the virtual table will be incomplete in client code.

The (un)solution: apply LIB_SHARED to the entire class, as it is typically suggested:

class LIB_SHARED C: public QObject { /* ... */ };

This solves linking problems, but the primary goal (eliminating unnecessary export table entries) is not reached, at least not for QObject-based classes.

The question: is there any way to achieve the desired result? I’ve tried messing a bit around the Q_OBJECT macro, with no success.

I hope for a solution that works on Linux systems too (assuming hidden symbol visibility as default), so .def files are not applicable. Hacks, however, are welcome 🙂

Any help is appreciated.

PS: Note that besides this problem is framed in a Qt environment, it can happen anywhere where a macro expansion is used to generate declarations, as in this case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:01:05+00:00Added an answer on May 30, 2026 at 2:01 pm

    Try to use pimpl idiom and export only public part. For example:

    class CPrivate;
    class LIB_SHARED C: public QObject {
      Q_OBJECT
    private: 
        CPrivate* m_private;
    public:
        ...
    };
    

    And create private class where placed all private (non exportable) stuff:

    class CPrivate : public QObject {
        Q_OBJECT
    public:
        void h();
    
    public slots:
        void i();
    }
    

    Then initialize and call private implementation from public class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As of now I have done effort estimation based on experience and recently using
How much effort would it take to migrate a large existing codebase from a
What is the effort to migrate from Blackfish to Firebird ? I use DBX4
In an effort to avoid potentially unexpected exceptions from a method (in the interest
How do convert effort estimate say in function points to a specific web framework
In the effort to learn more about applets and Java, I am experimenting making
I am making the effort to learn Vim. When I paste code into my
This is my first effort on solving the exercise. I gotta say, I'm kind
In an effort to 'clean up' my code - I was wondering if this
I've been making a concerted effort to improve my javascript skills lately by reading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.