The "QFrame * frame_1" that you declare in your MainWindow class is not the same as the "frame_1" widget you create in the UI file. You do understand that, right?
The "QFrame * frame_1" that you declare in your MainWindow class is not the same as the "frame_1" widget you create in the UI file. You do understand that, right?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Hi,
i can't understand that pls. why they are not the same? i draged from the qt designer as qframe and declared in mainwindow as qframe class.
thanks.
The QFrame variable is declared in your UI file ui_MainWindow.h. This file is automatically created by Qt's UIC compiler from the MainWindow.ui file, which you have #include-d in MainWindow.cpp. That QFrame is a member variable in the Ui::MainWindow class. You create an instance of that class in your MainWindow constructor:
Qt Code:
ui(new Ui::MainWindow) { ui->setupUi(this); // ... }To copy to clipboard, switch view to plain text mode
and the call to ui->setupUi() creates that QFrame. There is no code in your MainWindow class that creates the QFrame instances you declare in MainWindow itself.
If you still don't understand why the QFrame * frame_1 in MainWindow is not the same as the QFrame * frame_1 in Ui::MainWindow, you need to go back to your C++ book and read about namespaces.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Hi
this isn't a good idea saying to somone: you know nothing!! of corse, if i knew all, i wouldn't be in this forum. i want from you to gide me to something like qstackedwidget.. i would like to understand little about qt framework!
thanks
We are here to help with specific Qt programming problems, not to teach basic C++. I am sorry if this sounds rude, but you really -do- need to understand C++ programming in order to use Qt at all. The code that you posted shows that you have problems with some really basic concepts, like the difference between declaring a pointer variable as a member of a C++ class and how that pointer variable is assigned and used, and not understanding that two variables with the same name but in different namespaces are not the same variable..
I will admit that when I first started out with Qt about 10 - 12 years ago, I was puzzled about Qt classes and UI files. There is a lot of magic that happens inside of Qt at different times - when you design a UI using Qt Designer, when you build your project using Qt Creator or Visual Studio, and when you run it. Understanding what happens and when is important to be able to use Qt as part of your applications.
Qt is supported by a huge number of examples, tutorials, and other documentation. I would suggest you start with this and learn the basics of how to use Qt and look at the examples and tutorials.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
you are not interesting with your behaviour! this code you
insulting is generated by the qt designer. it isn't my code!!
i'm beginner you know and i'm understanding examples. this code
is working perfectly. i forgot to send the "firstdialog.ui" and
the "main()" function. when i click to the pushbutton, the
firstdialog window is appearing. what i wanted is that it apears
in the place of frame_3 of the mainwindow. but you are giving
responses like you want in this good forum(i think). this is my
last response for you,i wasted my time with somebody like you.
here are these 2 functions i forgot.
firstdialog.ui
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char* argv[])
{
QApplication app(argc,argv);
MainWindow w;
w.setFixedSize(800,700);
w.show();
return app.exec();
}
You have a QMainWindow and a QDialog. Both of these are intended to create a separate window on the desktop when show() (or exec()) is called... I assume this is what you see. Instead, when you click a button in the main window you want the content that is displayed in the current dialog to be shown as part of the content area of the main window. It's not clear whether that will be:
1. Replacing existing content in the "third frame". You generally use a QStackedWidget to show alternate widgets in the same layout space.
2. The "third frame" is normally hidden and only shown, with the dialog's contents, on demand.
Case 1 is demonstrated in the attached example based on yours. I mocked up the main window content. Flip between options in the stack using the two push buttons.
I changed your FirstDialog class to QWidget because it really is not a dialog. It is embedded in the main window designer ui by promoting page 2 of the stacked widget.
You will notice that the QFrame* member variables you put in the two headers are neither present nor needed.
Case 2 is handled differently and has more complicated implications for layout handling. Take a look at the Qt Extension Example for guidance.
Last edited by ChrisW67; 16th December 2018 at 03:56.
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
Hi,
first of all, I ask you to excuse me all (even d_stranz). i was giving up qt. i'm doing good things in c and a little in c++. i'm thinking qt is good and well designed. i come back to read all and will be back. thanks a lot chrisw67.
Bookmarks