Solved Help on Animated side tap option sliding dialog
-
@Faruq
Hi, good to hear.The parent is part of the ownership system.
http://doc.qt.io/qt-5/objecttrees.html
Its used both or Qt to know how the widgets on the screen is related and used for
drawing. ( if parent is hidden, all child are hidden too etc)
Its also used for cleaning up. Normally in c++ when you new something , you have to call delete on it
or you leak memory. Qt helps to make that easier, and the ownership system is used to keep track of
of the children and its owners will delete them.
So when you insert say a QPushButton on Window. When window is deleted, it deletes the button too.
(so you dont have to )The key is to assign a parent/owner when you create them
QPushButton *b = new QPushButton(this) << this being mainwindow
then its shown correctly and also being delete with Mainwindow. ( that main.cpp will delete) -
@mrjj IT WORKSSSSSSSSSSSSSS!!!! OMG THANKS.
-
@mrjj I decided to continue on and encountered another problem.
I am trying to access the parent ui pushButton from SubDisplay_1 (.cpp number 2).
the code I used is;
connect(parent->pushButton_2,SIGNAL(released()), this, SLOT(panelMovementToOri()));However, parent seems to only work with adjustment and NOT to access their pushButtons or so. (Ui Objects). Did I miss out something or a step?
-
On top of the above,
how do I access a child Ui objects (E.g. pushButton, etc) and their function from its parent .cpp? -
Anyone have any idea? Currently I am working/replacing the connect with these but to no avail:
-
connect(parent->pushButton_2,SIGNAL(released()), this, SLOT(panelMovementToOri()));
-
connect(MainWindow::ui->pushButton_2,SIGNAL(released()), this, SLOT(panelMovementToOri()));
-
Ui::MainWindow *ui123 ; (UNDER HEADER PUBLIC)
connect(ui123.pushButton_2,SIGNAL(released()), this, SLOT(panelMovementToOri()));
All of the above doesn't work as it says something along Error: invalid use of non-static data member or some other error.
All I need is to connect to the parent/other ui object QPushButton from this current .ccp file. Thus the missing blank would be as follows;
aaa.cpp
There is a QPushButton here. namely PushButton_1.bbb.cpp
connect( ????????? ,SIGNAL(released()), this, SLOT(panelMovementToOri()));where the ??? is the missing blank.
-
-
Hi
You cannot connect to inner widgets. Besides being bad design, its
not possible as the UI is private.
You can use signal and slots for it.
You can easy add new public signals and the outside can use those.Here is sample that pops a dialog that then ask mainwindow to change a tab on
a widget it holds.
Same method can be used for for any kind of activation from one class to other.https://www.dropbox.com/s/w1qo7xpjhhxjzhi/myotherdialog.zip?dl=0
-
@mrjj Hi mrjj! I tried it out however there are some other parts that I am unable to pull off such as closing the newly created dialog through modeless window/dialog. The //ADDED is the modification.
https://www.dropbox.com/s/pcmjsv9fx6ydz68/Faruq.myotherdialog.zip?dl=0
Thank you and patiently waiting for your help :)
-
@mrjj I think I got it! But I would still require someone to verify if I am making sense.
I place in connect button into the MyDialog::MyDialog and it finally pull off the close button. I believe it works because this specific function have its parent declare on top while the other functions (Void MyDialog:: "the rest of it") doesnt have the parent declaration. How can I declare so that the whole file can see "Parent" as a declared variable? Must i put it in the mydialog.h Header file?
mydialog.cpp
#include "mydialog.h" #include "ui_mydialog.h" #include "mainwindow.h" #include <QDebug> MyDialog::MyDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MyDialog) { ui->setupUi(this); this->setGeometry(parent->geometry().x()-(this->width()), parent->geometry().y(),this->width(),this->height()); connect(parent, SIGNAL(closetab()),this,SLOT(close())); // THE MOST IMPORTANT PART IS THE CONNECT. I believe it works because this specific function have its parent declare on top while the //other functions (Void MyDialog:: -the rest of it- doesnt have the parent declaration. }
-
Hi
There is always parent() call in any widget if you are inside other remember function.
this->parent() gives parent for any widget. ( it can be NULL)So in mainwindow, you press button to close MyDialog ?
-
@mrjj yup! my work is no longer in stale mode! I am working out and letting you know once I am done. Thank you! :) Rushing to finish and make you proud