[SOLVED] QMainWindow::QMainWindow: cannot access private member...
-
Hi folks, I have this time a new problem with this code:
@
class MainWindow : public QMainWindow
{
Q_OBJECTpublic: 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'
-
I think, I know where is the problem. I am not able to use operator =, am I right?
-
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.
-
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...
@ -
QObjects (and subclasses like QWidget) are unique entities - you cannot copy them.
-
[[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!
-
@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.