Solved Refresh QLCDNumber
-
So you are currently doing thing in the wrong sense and order.
The 3rd widget with its push button should not know anything about the second. From the looks of it, it should be instantiated and connected in the main function. Or alternatively be a member variable of your MainWindow class and be connect by the MainWindow itself.
As for your first widget, since it's a dialog, do you need to call it only once at the start of your application of multiple times ?
In any case, you can call it from within your MainWindow and handle its content there.
-
hi
With COUT, I see i can not recover the my instance with my get...
It tell me : QObject::connect: invalid null parameter
l'instance retournée est : 0000000000000000But when i set my instance, i have a good value on my member variable...
My get doesn't work ..To remember my problem, i created the instance for my second class and i would like to change value of QLCDNumber by an other class, so i created connect in the third class but this connect must be point on the same instance, so with get we could like success this ...
my variable membre in the first class :
private: Ui::window1 *ui; /*Always declare a pointer with 0 as address*/ Window018703 *m_window018703 = nullptr;
my instance created in first class we want to recover :
m_window018703 = new Window018703(); this->set_window018703(m_window018703); QObject::connect(ui->pushButtonOk, &QPushButton::clicked , m_window018703, &Window018703::windowView);
the set and get in my first class :
Window018703* window1::get_window018703() const { cout <<" l'instance retournée est : " << m_window018703 << endl; return m_window018703; } /**************************************************************************/ void window1::set_window018703(Window018703 *window018703) { cout <<" object depart set est : " << window018703 << endl; m_window018703 = window018703; cout <<" object arriver set est : " << m_window018703 << endl; }
and in my third class, i try to get this instance but it his value is null ... :
void Window018704::acces() { window1 *instance1 = new window1(); ; Window018703 *instance3 = new Window018703(); instance3 = instance1->get_window018703(); cout<<"voici l'instance retourné : "<< instance3<< endl; QObject::connect(ui->pushButton_018704, &QPushButton::clicked , instance3, &Window018703::set_lcdNumber_seatUp); }
erreur : QObject::connect: invalid null parameter
but when i cout my set, i have value .. :
object depart set est : 000001B0C0B90DA0
object arriver set est : 000001B0C0B90DA0 -
i have understand, when i do that :
window1 *instance1 = new window1(); ;
i re-created an instance and my member variable reset at null ptr ...edit :
I still do not know how to avoid that -
Hi
Yes, the error is that you create a new window1 instance.
And it never created a Window018703 as it is the other one.
You need the instance from main.
However, since this has caused tons of issues. i wonder if we could do it another way.
Using signals to show/hide the Window018703 created in MAIN so we get around the issue.
if you define 2 new SIGNALS in window1.
like
signals:
void ShowSecond();
void HideSecond();
and then didint main(int argc, char *argv[]) { QApplication app(argc, argv); window018703 TheWindow018703(); // new. the one you normally create in win1 TheWindow018703.hide(); // dont show yet window1 window1; // add new signals to this // hook new signal to TheWindow018703 show so we can emit ShowSecond and it will show connect(&window1, window1::ShowSecond, &TheWindow018703::show ); window1.show(); // show win1 but in slot DO NOT create new window018703 but call emit ShowSecond to show instance from main. Window018704 window3; connect( window3, xxxx , &TheWindow018703, xxxx) // connect lcd thing here window3.show(); return app.exec(); }
-
@mrjj
Hi
Ty!But i don't understand all ..
window018703 TheWindow018703(); // new. the one you normally create in win1
what is that ?? in my computer, this is doesn't work.
i think you would like do this :Window018703 o_window018703; o_window018703.hide();
secondly for me there missing 1 thing is this connect :
connect(&window1, window1::ShowSecond, &TheWindow018703::show );
and : &TheWindow018703::show make mistake...
i have created 2 signals in first window1 but in slot i emit Showsecond(), but HideSecond() are usfull for what ?
And for the LCD, it incremente by push on QPushButton so i don't understand this :
Window018704 window3;
connect( window3, xxxx , &TheWindow018703, xxxx) // connect lcd thing here
window3.show();thinks a lot ...
-
@martial123
Yep, small typos.
Didn't have a compiler at hand :)
yes i mean.
Window018703 o_window018703;The connect is wrong. i used the name of var , not class name. (as it should)
connect(&window1, window1::ShowSecond, &Window018703 ::show );HideSecond signal was just in case you wanted to hide it again. if you don't need that , you can skip it.
- And for the LCD, it incremente by push on QPushButton so i don't understand this :
well i was not sure what signal you use for that. but now mains know all of the classes so
you can use anything you like. all instances are in same place. -
@mrjj
hiConnect must have 4 argument no ??
i do that :QObject::connect(&o_window1, &window1::ShowSecond, &Window018703::show );
And i have no error but window018703 are not show when signal ShowSecond is emit.
If i do that :
QObject::connect(&o_window1, &window1::ShowSecond, &Window018703::windowView );
i replace &Window018703::show by &Window018703::windowView ( windowView is my slot to show window018703. When i do that, he tell me errors :
C:\Qt\5.11.2\msvc2017_64\include\QtCore\qobject.h:262: error: C2665: 'QObject::connect': none of the 4 overloads could convert all the argument types
and for the third window, i do that :
but error :
Window018704 o_window018704; //connect( window3, xxxx , &TheWindow018703, xxxx) // connect lcd thing here QObject::connect(ui->pushButton_018704, &QPushButton::clicked , o_window018703, &Window018703::set_lcdNumber_seatUp); o_window018704.show();
he don't know ui ...
edit []
I have succeeded to connect signal to show my second class in add a 4 argument :using namespace std; int main(int argc, char *argv[]) { QApplication app(argc, argv); Window018703 o_window018703; o_window018703.hide(); window1 o_window1; **QObject::connect(&o_window1, &window1::ShowSecond, &o_window018703, &Window01870~~3::windowView);** o_window1.show(); Window018704 o_window018704; //connect( window3, xxxx , &TheWindow018703, xxxx) // connect lcd thing here // QObject::connect(ui->pushButton_018704, &QPushButton::clicked , o_window018703, &Window018703::set_lcdNumber_seatUp); //o_window018704.show(); return app.exec(); }
now, i work on the third class ...
-
I HAVE DONE THIIIIIIISSS
Its work !!!! A Hundred TY !!!
My main now :
using namespace std; int main(int argc, char *argv[]) { QApplication app(argc, argv); Window018703 o_window018703; o_window018703.hide(); Window018704 o_window018704; o_window018704.hide(); window1 o_window1; QObject::connect(&o_window1, &window1::ShowSecond, &o_window018703, &Window018703::windowView); QObject::connect(&o_window1, &window1::ShowThrid, &o_window018704, &Window018704::windowView); o_window1.show(); QObject::connect(&o_window018704, &Window018704::incremente , &o_window018703, &Window018703::set_lcdNumber_seatUp); return app.exec(); }
by my third class, the signal emit is : &Window018704::incremente.
it is emit in slot who dechanche by that :QObject::connect(ui->pushButton_018704, &QPushButton::clicked , this, &Window018704::acces);
and the slot :
void Window018704::acces() { emit incremente(); }
So its work well !!
ty for all of your time peoples!I marque down solved, and i indicate wich comment has help me .
See you -
Hi
Super. Good work.!
So now you have learned one of the top questions there.
How to use Window X from Window Y :) -
@mrjj
Yes ! Thank's !
In future, i will probably have other questions, I would be sure to ask you :)
good day !