Originally Posted by
bithub
Yes, that is possible. You can create a class object anywhere as long as its constructor is public.
Yes, the constructor is public.
Thanks.
Next question:
I have tried to create a class object inside a member function (of the first dialog class), but keep getting compiler errors. The error I'm getting now suggests that a private slot inside the second dialog's class is not getting called for some reason, because it gives me a message something like
"Something forbids declaration of "QLineEdit" with no type"
or something to that effect (I'm don't remember the exact error message). Now the line its referring to looks like the following in the second dialog's class:
Code:
QLineEdit* lineEdit;
As you can see, its a pointer to type "QLineEdit" (a special QT class). Now, it shouldn't be giving me that error message seeing as its a type included in a QT header file that included, and so it indicates that its not getting to the code I'm using to use "lineEdit". Now, I figure the reason is the second dialog's class is not being "built" until the nextClicked() function (which is where I created the object of the second dialog's class) is called, which makes sense. In other words, what I'm trying to say here, is, the second dialog's members must not be actually created until the Next button is clicked, and for some reason, the compiler doesn't like this (and I don't know why).
The reason I think that is the case, is because I have tried creating the object of the second dialog's class inside int main(), and the compiler does not give me the error I mentioned above...it only appears when I try to create the object of the class inside the member function of the other class.
Anyway, I can probably figure that one out myself, but thought I would just go ahead and mention it, in case anyone here has any thoughts on the matter.
Another problem is:
Code:
TextToSpeechDialog1* dialog = new TextToSpeechDialog1;
dialog->show();
This code works fine, and causes the first class's (TextToSpeechDialog1) dialog to be shown.
However, in order to hide the first dialog when the second dialog is called, I tried to do this
Code:
void TextToSpeechDialog1::nextClicked() {
TextToSpeechDialog2* dialog2 = new TextToSpeechDialog2;
dialog->close(); //close() is a function that hides QWidgets from view, but does not delete
dialog2->show();
}
But the compiler will give me a message saying "dialog" was not declared in that scope. So how do I get around this, and hide "dialog" (the first dialog's class's object) from inside dialog itself?
Is this even possible? I guess its recursion, but I don't know how to work it.