Inheritance with multiple windows.
-
Hi, you need a copy of MainWindow's this pointer, i.e. you cannot access the words QList using "MainWindow::" prefix, instead you have to use a copy of the this pointer. for example:
@
pMainWindow->words.append(st):
@To get the this pointer into your Editor class, you can do like the code ui->setupUI(), it copies the this pointer into the Ui_MainWindow class.
-
I used this code:
@MainWindow *pMainWindow;
pMainWindow->words.append(st);@and the program unexpectedly crashed. (I am using Windows 7.)
I know that pointers need to be initialized, but I do not know what to do.
Thank you for the response.
-
Well, I think that's because you didn't allocated the space for you pointer. So you try this:
@
MainWindow *pMainWindow = new MainWindow;
pMainWindow->words.append(st);
@
You should give I look at this:
http://www.cplusplus.com/doc/tutorial/pointers/
http://www.cplusplus.com/doc/tutorial/dynamic/ -
It seems you're still struggling with the basics of c++, it might help to brush up on that first.
-
I understand that mistake, using 'new'.
Can somebody explainhow to get the 'this' pointer from the MainWindow class in my Editor class?
Inheritance will not be solution, I think, because the Editor class already inherits the QDialog class.
-
Hi, you could add a function to your Editor class, that accepts a MainWindow flavored this pointer, like this:
@
void setMainWindowPtr(MainWindow *p);
@ -
What should be in the body of the function?
Because the parameter for the function is a MainWindow, I would have to create a MainWindow variable, right?
-
A variable that is a pointer to a MainWindow.
i.e.
@
MainWindow *pMw;
@
and such...May I ask what your programming experience is?
I would respectfully suggest that if you are just learning C++ you will may find it difficult to learn both at the same time. -
I learned C++ about one year ago, then learned Java, and now working on learning Android Programming.
-
I see. Well is is good to know several useful languages. Good luck with your Qt work.