Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QMainWindow::QMainWindow: cannot access private member...
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QMainWindow::QMainWindow: cannot access private member...

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 6.0k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Peppy
    wrote on last edited by
    #1

    Hi folks, I have this time a new problem with this code:
    @
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

     public:
                MainWindow(Qt::WindowFlags f = 0);
    

    }; // <== Here, I get the problem.
    @

    This code is working, because it is in DLL and it successfully compile it. But, when I try to compile an App which uses this code it says:

    bq. C:\Projects\Project\MainWindow.h:17: error: C2248: 'QMainWindow::QMainWindow' : cannot access private member declared in class 'QMainWindow'

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      I think, I know where is the problem. I am not able to use operator =, am I right?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        The code snippet is completely ok. Your error must be from somewhere else. As you have pasted only 7 lines, but your error is on line 17 (according to the pasted error message), there is something important missing from your snippet.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peppy
          wrote on last edited by
          #4

          There was just encapsulation into namespaces.
          Well, I am not able to copy that object with operator =... I had in code:
          @
          extern "C" {

          DLL_EXPORT MainWindow exportMainWindow()
          {
          return MainWindow(0,0);
          }
          @

          And in Application was code:
          @
          typedef MainWindow (*MainWindowHandler) ();
          MainWindowHandler mainWindow = (MainWindowHandler) lib->resolve("exportMainWindow");

          MainWindow mW = mainWindow(); // <= copying object is not acceptable.
          // 'operator =' and Constructor() are private...
          @

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            QObjects (and subclasses like QWidget) are unique entities - you cannot copy them.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              [[Doc:QObject]]s canot be passed as value types, but only as pointers:

              @
              MainWindow* exportMainWindow()
              {
              return new MainWindow(0);
              }
              @

              But be aware that you need to delete the object eventually, and - much more important - that you may run into memory management issues on Windows, especially when mixing C and C++ code across library boundaries. Watch out!

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Peppy
                wrote on last edited by
                #7

                @Volker: I am not mixing C and C++ code. Just QLibrary needs this addition to work fine (you mean "extern C" ?) because using CDECL as calling convention.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved