Results 1 to 12 of 12

Thread: staticMetaObject

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: staticMetaObject

    My coworker wants to confirm this with Qt Support, but it looks like he found a solution.

    For anyone else who has this problem, I'll explain as best I can his answer.

    Between Qt 3 and Qt 4, the Q_OBJECT macro underwent some changes. In Qt 3, the macro made a static struct in a private section, then made accessor and modifier functions.
    In Qt 4, there's now a static const struct in the public section. Don't ask me how exactly that creates errors, but here's the short version:

    In Qt 3, it was perfectly valid to have a class with the Q_OBJECT macro, and then have a child class that also has Q_OBJECT. In Qt 4, it is not. So just remove Q_OBJECT from the child class and it will still work.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: staticMetaObject

    Quote Originally Posted by Tiber View Post
    In Qt 3, it was perfectly valid to have a class with the Q_OBJECT macro, and then have a child class that also has Q_OBJECT. In Qt 4, it is not. So just remove Q_OBJECT from the child class and it will still work.
    Huh? That's not true. QWidget has Q_OBJECT declared. If what you are saying was true, you couldn't have any subclass of QWidget that implements new signals, slots or properties. And that's obviously not the case. I still say you have a problem with moc and linker.

  3. #3
    Join Date
    Apr 2008
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: staticMetaObject

    Actually you're right. It compiles (which I thought it wouldn't do without Q_OBJECT), but I haven't tested it. I got a little overeager when my coworker said he found a solution, and didn't stop to think about it. Chalk it up to absentmindedness.

    Anyway, looking at it more, you had the right idea. The problem was that some preprocessor definitions that were needed (including the one necessary for __declspec(dllimport)) weren't in the project file. Somehow everything managed to work for everyone else still using the Qt 3 build, but not for me working on the Qt 4 port. Just another unexplained mystery of the universe.

    Anyway, thanks for your help.

  4. #4
    Join Date
    Jan 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: staticMetaObject

    Hi,
    I had a similar problem with deriving my own classes from QtAbstractPropertyManager and QtAbstractEditorFactory for the customization of Qtpropertybrowser.

    Error messages while linking in VS2008 were:

    1>moc_QtImgCoordPropertyManager.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QtAbstractPropertyManager::staticMetaObject" (?staticMetaObject@QtAbstractPropertyManager@@2UQM etaObject@@B)
    1>moc_QtPointImgEditFactory.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QtAbstractEditorFactoryBase::staticMetaObject" (?staticMetaObject@QtAbstractEditorFactoryBase@@2U QMetaObject@@B)

    including "#define QT_QTPROPERTYBROWSER_IMPORT" in the header files of the derived classes resolved the problem (the effect is that it changes the QT_QTPROPERTYBROWSER_EXPORT define in file qtpropertybrowser\src\qtpropertybrowser.h

    Hope this info can be helpful for somebody.

  5. #5
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: staticMetaObject

    I just found what is this problem about and how to solve it. I`m changing big project from QT3 to QT4 - and last mistakes was :
    "error LNK2001: unresolved external symbol "public: static struct QMetaObject const <CLASS_NAME>::staticMetaObject" (?staticMetaObject@<CLASS_NAME>@@2UQMetaObject@@B) "

    The most closest to solution was 'Tiber' here :"The problem was that some preprocessor definitions that were needed (including the one necessary for __declspec(dllimport)) weren't in the project file. Somehow everything managed to work for everyone else still using the Qt 3 build, but not for me working on the Qt 4 port. Just another unexplained mystery of the universe."
    and 'nobledeveloper' from other forum: http://www.qtforum.org/article/17697...externals.html

    At first I wasn't so sure that they are correct and I was trying to find the reason from other ways. I created tested solution with 2 dll`s . With such classes:
    parent ( C/C++ -> Preprocessor Difinitions: ...TESTLIB_LIB; ):

    #ifdef TESTLIB_LIB
    # define TESTLIB_EXPORT Q_DECL_EXPORT
    #else
    # define TESTLIB_EXPORT Q_DECL_IMPORT
    #endif
    class TESTLIB_EXPORT testLib: public QObject
    {
    Q_OBJECT
    ....
    }

    child ( C/C++ -> Preprocessor Difinitions: ...TEST2LIBCHILD_LIB; ):

    #ifdef TEST2LIBCHILD_LIB
    # define TEST2LIBCHILD_EXPORT Q_DECL_EXPORT
    #else
    # define TEST2LIBCHILD_EXPORT Q_DECL_IMPORT
    #endif

    class TEST2LIBCHILD_EXPORT test2LibChild:
    public testLib
    {
    Q_OBJECT
    ...
    }


    and I get no errors...
    But if I add to child "C/C++ -> Preprocessor Difinitions: TESTLIB_LIB" I will get such a link error "error LNK2001: unresolved external symbol "public: static struct QMetaObject const testLib::staticMetaObject" (?staticMetaObject@testLib@@2UQMetaObject@@B)"

    To solve my problem I added for each sub-project dlldefslocal.h with corresponding defines , for example:

    #ifdef DVL_HIO_DIALOGIO_PLUGIN
    # define DVL_HIO_DIALOGIO_PLUGIN_EXPORT Q_DECL_EXPORT
    #else
    # define DVL_HIO_DIALOGIO_PLUGIN_EXPORT Q_DECL_IMPORT
    #endif


    It looks like ,if child uses the same define as parent then parent class gets __declspec(dllimport) and we have such a error like LNK2001, why it was normally for QT3 - I think some changes for QObject are resulted in an error for old defines.
    Last edited by dresha48; 11th May 2011 at 13:48.

  6. #6
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: staticMetaObject

    Small addition:
    if you already have big project where you get such errors (I think it only could happens if you are changing yours projects from qt3 to qt4) - just use for parent classes different macro (not like for the children) , where you got errors - thats all . For exapmle I added for all parents which gives me LNK2001 error :
    add to parent classes from same dll ( in dll project property add to C/C++ ->Prprocessor->Preprocessor Definitions : DVL_DVL2_DLL_API; ):

    #include "dllDefines.h"

    class DVL_DVL2_API someParentClassName{...};

    dllDefines.h :

    #ifdef DVL_DVL2_DLL_API
    #define DVL_DVL2_API __declspec(dllexport)
    #else
    #define DVL_DVL2_API __declspec(dllimport)
    #endif
    Last edited by dresha48; 13th May 2011 at 11:35.

Similar Threads

  1. Dereferencing a NULL Pointer for staticMetaObject?
    By hyling in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 00:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.