[C++] Call a pushbutton and a LineEdit
-
@jsulm thanks between the answers and you message, this is what i understand after few minutes :D
I understand but the documentation never show how to call and UI button by using ui->. :SMy last problem concerns this line :
connect(&compteur_, SIGNAL(envoyerQuantite(int)), quantite, SLOT(setNum(int)));
Thanks -
@Cervo2paille If you read the error message you should know what the problem is: the third parameter is a QString, so quantite is a QString, right? That can't work.
And again: please use new connect syntax... -
Ok i understand :
connect(&compteur_, SIGNAL(envoyerQuantite(int)), ui->quantite, SLOT(setNum(int)));
I got again an error on this line :
But this is a classic class :
Thanks for advance.
PS : don't anwer i'm looking for
-
@Cervo2paille
Looks likecompteur_
(thecompteur
class) is not aQObject
, and you can only useQObject
s for signals or slots. -
In fact it was a simple class
I put it in QObjet :#ifndef COMPTEUR_H #define COMPTEUR_H #include <QObject> class compteur: public QObject { Q_OBJECT public: compteur(); int getQuantite(); void augmenterQuantite(); void reduireQuantite(); signals: int envoyerQuantite(int); private: int quantite_; }; #endif // COMPTEUR_H
But i got many error in my compteur.cpp :
"Multiple definition of compteur". I clean, recompilate my project...
Any idea? Thanks -
@Cervo2paille said in [C++] Call a pushbutton and a LineEdit:
I clean
Did you also try to delete the build folder?
Please post the error messages as text, not images...
-
@jsulm yes i did, but nothing change.
My compteur.cpp :
#include "compteur.h" compteur::compteur():quantite_(0) { } int compteur::getQuantite(){ return quantite_; } void compteur::augmenterQuantite(){ quantite_++; emit envoyerQuantite(quantite_); } void compteur::reduireQuantite(){ quantite_--; emit envoyerQuantite(quantite_); }
Thanks
-
@Cervo2paille
I do not know whether it would cause the error messages you see, but where does yourcompteur()
constructor call the baseQObject
constructor? -
@JonB Sorry i don't understand your question.
I got the filling that put my class like a ": public QObject" was enough.If you need more information see my compteur.h :
#ifndef COMPTEUR_H #define COMPTEUR_H #include <QObject> class compteur: public QObject { Q_OBJECT public: compteur(); int getQuantite(); void augmenterQuantite(); void reduireQuantite(); signals: int envoyerQuantite(int); private: int quantite_; }; #endif // COMPTEUR_H
Thanks
-
@Cervo2paille
Sorry, I was mistaken. The more usual way to inherit fromQObejct
is:// .h file explicit compteur(QObject *parent = nullptr); // .cpp file compteur::compteur(QObject *parent = nullptr) : QObject(parent)
But if you really do not want to accept a parent for
compteur
your code is OK without any explicitQObject()
call, so that is not the cause of your error messages.Does your
ajouterproduit.h
file have#include "compteur.h"
at its head? The error message seems to be complaining inajouterproduit.cpp.obj
. And btw, how did you manage to generate a file with a.cpp.obj
extension?! -
I done an error, an include of .cpp
It works !Thanks all for your time.
-
@Cervo2paille said in [C++] Call a pushbutton and a LineEdit:
I done an error, an include of .cpp
Yeah, not a good idea :)