Results 1 to 9 of 9

Thread: [RESOLVED] Help in using private classes

  1. #1
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [RESOLVED] Help in using private classes

    I make as it is written here: http://techbase.kde.org/Policies/Lib...ointer_Example

    mybaseclass.h
    Qt Code:
    1. #ifndef MYBASECLASS_H
    2. #define MYBASECLASS_H
    3.  
    4. #include <QObject>
    5.  
    6. class MyBasePrivateClass;
    7. class MyBaseClass : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. MyBaseClass(QObject *parent = 0);
    12. virtual ~MyBaseClass();
    13. void setParam(int val);
    14. int param() const;
    15. protected:
    16. MyBasePrivateClass * const d_ptr;
    17. //MyBaseClass(MyBasePrivateClass &dd, QObject *parent);
    18. private:
    19. Q_DECLARE_PRIVATE(MyBaseClass)
    20. Q_DISABLE_COPY(MyBaseClass)
    21. };
    22.  
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    mybaseclass.cpp
    Qt Code:
    1. #include "mybaseclass.h"
    2.  
    3.  
    4. class MyBasePrivateClass
    5. {
    6. Q_DECLARE_PUBLIC(MyBaseClass)
    7. public:
    8. MyBasePrivateClass() { m_param = 0; }
    9. virtual ~MyBasePrivateClass() {}
    10. int m_param;
    11. MyBaseClass *q_ptr;
    12. };
    13.  
    14.  
    15. MyBaseClass::MyBaseClass(QObject *parent)
    16. : QObject(parent), d_ptr(new MyBasePrivateClass)
    17. {
    18. // Q_D(MyBaseClass);
    19. }
    20.  
    21. MyBaseClass::~MyBaseClass()
    22. {
    23. delete d_ptr;
    24. }
    25.  
    26. void MyBaseClass::setParam(int val)
    27. {
    28. Q_D(MyBaseClass);
    29. d->m_param = val;
    30. }
    31.  
    32. int MyBaseClass::param() const
    33. {
    34. Q_D(const MyBaseClass);
    35. return d->m_param;
    36. }
    To copy to clipboard, switch view to plain text mode 

    in console written :
    D:\projects\Private_test\src>make
    g++ -c -O2 -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_CORE_LIB -D
    QT_THREAD_SUPPORT -I"D:/Qt/4.1.1/include/QtCore" -I"D:/Qt/4.1.1/include" -I"D:/Qt/4.1.1/include/Acti
    veQt" -I"build\moc" -I"." -I"D:/Qt/4.1.1/mkspecs/win32-g++" -o build\obj\mybaseclass.o mybaseclass.c
    pp
    In file included from mybaseclass.cpp:1:
    mybaseclass.h:19: error: ISO C++ forbids declaration of `MyBaseClassPrivate' with no type
    mybaseclass.h:19: error: `MyBaseClassPrivate' declared as an `inline' field
    mybaseclass.h:19: error: expected `;' before '*' token
    mybaseclass.h:19: error: expected `;' before "inline"
    mybaseclass.h:19: error: ISO C++ forbids declaration of `MyBaseClassPrivate' with no type
    mybaseclass.h:19: error: `MyBaseClassPrivate' declared as an `inline' field
    mybaseclass.h:19: error: expected `;' before '*' token
    mybaseclass.h:19: error: expected `;' before "friend"
    D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function `void MyBaseClass:
    :setParam(int)':
    D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h:99: error: `QObjectPrivate* QObject::d
    _func()' is private
    mybaseclass.cpp:28: error: within this context
    mybaseclass.cpp:28: error: cannot convert `QObjectPrivate*' to `MyBaseClassPrivate* const' in initia
    lization
    mybaseclass.cpp:29: error: invalid use of undefined type `struct MyBaseClassPrivate'
    mybaseclass.h:19: error: forward declaration of `struct MyBaseClassPrivate'
    D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h: In member function `int MyBaseClass::
    param() const':
    D:/Qt/4.1.1/include/QtCore/../../src/corelib/kernel/qobject.h:99: error: `const QObjectPrivate* QObj
    ect::d_func() const' is private
    mybaseclass.cpp:34: error: within this context
    mybaseclass.cpp:34: error: cannot convert `const QObjectPrivate*' to `const MyBaseClassPrivate* cons
    t' in initialization
    mybaseclass.cpp:35: error: invalid use of undefined type `const struct MyBaseClassPrivate'
    mybaseclass.h:19: error: forward declaration of `const struct MyBaseClassPrivate'
    mingw32-make: *** [build\obj\mybaseclass.o] Error 1
    Help Please Already 2 days tormented

    PS: Attach project
    Attached Files Attached Files
    Last edited by kuzulis; 25th August 2009 at 07:32.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help in using private classes

    Use QSharedDataPointer. You achieve the same thing, only it saves you the headache .
    Last edited by franz; 25th August 2009 at 07:15.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help in using private classes

    nonono! I want it private classes!

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help in using private classes

    Quote Originally Posted by kuzulis View Post
    nonono! I want it private classes!
    OK, then you need to solve your errors. To start with, name your private class MyBaseClassPrivate instead of MyBasePrivateClass.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help in using private classes

    and whence came MyBaseClassPrivate? o_O

  6. #6
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help in using private classes

    аааааа!!!
    It is necessary to change the name of the class!

    Thank you very much! Question resolved!

  7. #7
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [NOT RESOLVED] Help in using private classes

    No working this test project, write in console:

    build\obj\mybaseclass.o(.text+0x0):mybaseclass.cpp : multiple definition of `MyBaseClass::MyBaseClass
    (QObject*)'
    build\obj\mybaseclass.o(.text+0x0):mybaseclass.cpp : first defined here
    build\obj\mybaseclass.o(.text+0xd0):mybaseclass.cp p: multiple definition of `MyBaseClass::MyBaseClas
    s(QObject*)'
    build\obj\mybaseclass.o(.text+0xd0):mybaseclass.cp p: first defined here
    build\obj\mybaseclass.o(.text+0x1a0):mybaseclass.c pp: multiple definition of `MyBaseClass::MyBaseCla
    ss(MyBaseClassPrivate&, QObject*)'
    build\obj\mybaseclass.o(.text+0x1a0):mybaseclass.c pp: first defined here
    build\obj\mybaseclass.o(.text+0x1d0):mybaseclass.c pp: multiple definition of `MyBaseClass::MyBaseCla
    ss(MyBaseClassPrivate&, QObject*)'
    build\obj\mybaseclass.o(.text+0x1d0):mybaseclass.c pp: first defined here
    build\obj\mybaseclass.o(.text+0x200):mybaseclass.c pp: multiple definition of `MyBaseClass::~MyBaseCl
    ass()'
    build\obj\mybaseclass.o(.text+0x200):mybaseclass.c pp: first defined here
    build\obj\mybaseclass.o(.text+0x2c0):mybaseclass.c pp: multiple definition of `MyBaseClass::~MyBaseCl
    ass()'
    build\obj\mybaseclass.o(.text+0x2c0):mybaseclass.c pp: first defined here
    build\obj\mybaseclass.o(.text+0x380):mybaseclass.c pp: multiple definition of `MyBaseClass::~MyBaseCl
    ass()'
    build\obj\mybaseclass.o(.text+0x380):mybaseclass.c pp: first defined here
    build\obj\mybaseclass.o(.text+0x450):mybaseclass.c pp: multiple definition of `MyBaseClass::setParam(
    int)'
    build\obj\mybaseclass.o(.text+0x450):mybaseclass.c pp: first defined here
    build\obj\mybaseclass.o(.text+0x470):mybaseclass.c pp: multiple definition of `MyBaseClass:aram() c
    onst'
    build\obj\mybaseclass.o(.text+0x470):mybaseclass.c pp: first defined here
    build\obj\main.o(.text+0x8d):main.cpp: undefined reference to `MyClass::MyClass(QObject*)'
    collect2: ld returned 1 exit status
    mingw32-make: *** [release\testprivate.exe] Error 1
    Heelp mee!

    PS: attach arc
    Attached Files Attached Files

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [RESOLVED] Help in using private classes

    comment these lines
    Qt Code:
    1. //MyClass::MyClass(MyClassPrivate &dd, QObject *parent)
    2. // : MyBaseClass(dd, parent)
    3. //{
    4. //}
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [RESOLVED] Help in using private classes

    Quote Originally Posted by spirit View Post
    comment these lines
    Qt Code:
    1. //MyClass::MyClass(MyClassPrivate &dd, QObject *parent)
    2. // : MyBaseClass(dd, parent)
    3. //{
    4. //}
    To copy to clipboard, switch view to plain text mode 
    no, The problem was:
    src.pro:
    - SOURCES = mybaseclass.cpp mybaseclass.cpp main.cpp
    + SOURCES = mybaseclass.cpp myclass.cpp main.cpp

    myclass.h:
    protected:
    - MyClass(MyClass &dd, QObject *parent);
    + MyClass(MyClassPrivate &dd, QObject *parent);

Similar Threads

  1. private classes in QT
    By talk2amulya in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2009, 17:26
  2. Multiple Classes setText Update
    By Msnforum in forum Qt Programming
    Replies: 5
    Last Post: 30th January 2009, 15:40
  3. Error signal connection between 2 classes
    By mattia in forum Newbie
    Replies: 6
    Last Post: 31st October 2007, 09:36
  4. Why does Qt use Private classes?
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2006, 22:11
  5. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.