Unsolved QListWidget connect to QPushButton
-
@Eleonore said in QListWidget connect to QPushButton:
Hi" connect, momentPtr and panierPtr, what is it and what does "ptr" mean?"
Hi
Ptr just means pointer. we need pointers to the classes to connect them.- new panier(this).
Some place this window is created.
likepanier *ThePanier = new panier(this). ThePanier ->show();
or something like that.
We can call it the creation place.
and we need "ThePanier"the same goes for the moment class. we also need a pointer to an instance
to connect.Well it looks good. Made me feel like eating one :)
-
@mrjj
Hi, I tried doing it myself before asking you for help, my problem is connect( momentPtr,&moment::ProductSelected, panierPtr, panier::ProductSelected ); Qt doesn' recongnize momentPtr and panierPtr. I tried to pu something else instead but nothing works. I think that there is also a problem with my ProductSelected, wwhat I understand is that Qt says it's not defined.
About the ThePanier ->show(); it's a little complicated because it's located in a function called "void opened order, void MainWindow::ouvrircommande()
{
com = new commander();
com->show();
com ->setFixedSize(1065,768);
com->move(0,0);
panier *pan = new panier;
pan ->show();
pan->setFixedSize(300,768);
pan->move(1066,0);}
This function is located in my mainwindow.cpp to open my two windows (the one with written our product and the card) at the same time.
Thanks for your help and my hope my teacher will think the same thing as you about my interface. -
@Eleonore said in QListWidget connect to QPushButton:
Qt doesn' recongnize momentPtr and panierPtr
Please post the relevant code and the while error message.
-
-
@Eleonore Next time please post text instead of screenshots.
I can't see where momentPtr and panierPtr are declared? -
@jsulm
I didn't declare them because I'm not sure I understand what I should put at momentPtr, I don't know if I've already declared them under another name or if I have to declare something new. And if I have to declare, I don't know how and where to do it. -
Hi. Good you tried first :)
Well those are just dummy names.
It just means a pointer to the class
so maybe here you have both ?
{ com = new commander(); <<< is this MOMENT class ? com->show(); com ->setFixedSize(1065,768); com->move(0,0); panier *pan = new panier; <<<< this is the panierPtr pointer pan ->show(); pan->setFixedSize(300,768); pan->move(1066,0); }
-
@mrjj
I kind of knew that it was the pointer, I arleady tried to replace it at that moment but it shows be an error message "use of undeaclared identifier "pan". I have this error message because this part of the code {
com = new commander(); <<< is this MOMENT class ?
com->show();
com ->setFixedSize(1065,768);
com->move(0,0);
panier *pan = new panier; <<<< this is the panierPtr pointer
pan ->show();
pan->setFixedSize(300,768);
pan->move(1066,0);}
is in my main.cpp but this part of code connect( momentPtr,&moment::ProductSelected, panierPtr, panier::ProductSelected ); is in my panier.cpp.
And I don't think I created a pointer for my QPushbutton, I just named it button that I declared in my void moment::ButtonProductClicked(). -
@Eleonore
Hi
well we need both a panier pointer and a moment pointer to connect them.its impossible to guess at when i dont have whole project.
so if you have the MOMNET pointer in panier it could work.
also do understand that if inside the panier , then you can use "this" in place of the pointer
Did you read this ?
https://doc.qt.io/qt-5/signalsandslots.htmlIts not complicated but yo udo need a place where both classes are known to connect them.
That is often in MainWindow or some commen place.
Sometimes in main.cppBut i cant say where to do it as i dont know where you NEW a moment instance.
also i guess that
com = new commander();
is another class. so you dont seem to make a MOMENT in main.cpp so it has to be some other place -
@mrjj
Thanks a lot for your help. Unfortunately, after all of this help I still can't create this interraction. I have to hand in my project tonight so I'll just explain that I couldn' t do this part. I hope this conversation can help others in the future.
Thanks a lot!