How to change the value of variables of another class using QPushButton?how can I hide a widget that generated a signal in qtAdd button click handler in Qt project, Visual StudioQStackedWidget navigation from page to pageHow to set text into Label in UI which is loaded by QUiLoaderHow to change window title and central widget in Qt?Qt: Accessing the signals/slots of a widget generated by uitools/uiloaderInheritence and Qt signalsC++/QT valueChanged(int) signal when spinbox widget being createdQEvent Signal and SlotIt it right way to user a global QObject for cross signal/slot forward
Make utility using LINQ
Can I get a PhD for developing an educational software?
Why is the UK so keen to remove the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?
1mth baby boy keeps peeing through diapers, sometimes diper seems practically unused
Changing JPEG to RAW to use on Lightroom?
Is the negative potential of 書く used in this sentence and what is its meaning?
Half filled water bottle
Unlock your Lock
Is first Ubuntu user root?
Why can't you reverse the order of the input redirection operator for while loops?
Was the Boeing 2707 design flawed?
Is it legal for source code containing undefined behavior to crash the compiler?
Papers on arXiv solving the same problem at the same time
How to sort a dictionary of lists and get the corresponding keys?
What is the meaning of “these lederhosen are riding up my Bundesliga”?
How to get trace to get a cylinder when I rotate a rectangle?
Prevent use of CNAME record for untrusted domain
How does the OS tell whether an "Address is already in use"?
How to say "I only speak one which is English." in French?
How do you capitalize agile costs with less mature teams?
Did Dr. Hannibal Lecter like Clarice or was he attracted to her?
What do Teignmouth, Paris, Ulm, Auxerre, Brunswick, Beaumont-en-Auge, and Ryazan have in common?
Beginner to guitar playing - where should I begin?
What stops you from using fixed income in developing countries?
How to change the value of variables of another class using QPushButton?
how can I hide a widget that generated a signal in qtAdd button click handler in Qt project, Visual StudioQStackedWidget navigation from page to pageHow to set text into Label in UI which is loaded by QUiLoaderHow to change window title and central widget in Qt?Qt: Accessing the signals/slots of a widget generated by uitools/uiloaderInheritence and Qt signalsC++/QT valueChanged(int) signal when spinbox widget being createdQEvent Signal and SlotIt it right way to user a global QObject for cross signal/slot forward
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm writing a code that i used QWidget to create the widget that i wanted and later i set this widget as a central widget.
So far so good, but in the widget i had buttons, that if one of them was clicked it changed a string variable value.
After that i set this as a central widget, i created the same buttons in the MainWindow, but i can't change the values of the variables that i want anymore :(
.....
linha_button=new QPushButton(this);
linha_button->setGeometry(QRect(QPoint(41,924),QSize(40,40)));
linha_button->setIcon(QIcon(url_linha));
linha_button->setIconSize(QSize(30,30));
linha_button->setCheckable(true);
QObject::connect(linha_button, SIGNAL (clicked()), this, SLOT (lihaButton()));
void MainWindow::lihaButton()
Diagrama::modo="trafo";
The variable modo is declared in the widget named Diagrama.
This code don't execute, the error is:
invalid use of non=static data member 'modo'
How can I fix this??
c++ qt qt5
add a comment |
I'm writing a code that i used QWidget to create the widget that i wanted and later i set this widget as a central widget.
So far so good, but in the widget i had buttons, that if one of them was clicked it changed a string variable value.
After that i set this as a central widget, i created the same buttons in the MainWindow, but i can't change the values of the variables that i want anymore :(
.....
linha_button=new QPushButton(this);
linha_button->setGeometry(QRect(QPoint(41,924),QSize(40,40)));
linha_button->setIcon(QIcon(url_linha));
linha_button->setIconSize(QSize(30,30));
linha_button->setCheckable(true);
QObject::connect(linha_button, SIGNAL (clicked()), this, SLOT (lihaButton()));
void MainWindow::lihaButton()
Diagrama::modo="trafo";
The variable modo is declared in the widget named Diagrama.
This code don't execute, the error is:
invalid use of non=static data member 'modo'
How can I fix this??
c++ qt qt5
add a comment |
I'm writing a code that i used QWidget to create the widget that i wanted and later i set this widget as a central widget.
So far so good, but in the widget i had buttons, that if one of them was clicked it changed a string variable value.
After that i set this as a central widget, i created the same buttons in the MainWindow, but i can't change the values of the variables that i want anymore :(
.....
linha_button=new QPushButton(this);
linha_button->setGeometry(QRect(QPoint(41,924),QSize(40,40)));
linha_button->setIcon(QIcon(url_linha));
linha_button->setIconSize(QSize(30,30));
linha_button->setCheckable(true);
QObject::connect(linha_button, SIGNAL (clicked()), this, SLOT (lihaButton()));
void MainWindow::lihaButton()
Diagrama::modo="trafo";
The variable modo is declared in the widget named Diagrama.
This code don't execute, the error is:
invalid use of non=static data member 'modo'
How can I fix this??
c++ qt qt5
I'm writing a code that i used QWidget to create the widget that i wanted and later i set this widget as a central widget.
So far so good, but in the widget i had buttons, that if one of them was clicked it changed a string variable value.
After that i set this as a central widget, i created the same buttons in the MainWindow, but i can't change the values of the variables that i want anymore :(
.....
linha_button=new QPushButton(this);
linha_button->setGeometry(QRect(QPoint(41,924),QSize(40,40)));
linha_button->setIcon(QIcon(url_linha));
linha_button->setIconSize(QSize(30,30));
linha_button->setCheckable(true);
QObject::connect(linha_button, SIGNAL (clicked()), this, SLOT (lihaButton()));
void MainWindow::lihaButton()
Diagrama::modo="trafo";
The variable modo is declared in the widget named Diagrama.
This code don't execute, the error is:
invalid use of non=static data member 'modo'
How can I fix this??
c++ qt qt5
c++ qt qt5
edited Mar 27 at 20:21
ΦXocę 웃 Пepeúpa ツ
35.4k12 gold badges43 silver badges68 bronze badges
35.4k12 gold badges43 silver badges68 bronze badges
asked Mar 27 at 20:00
Lukas MüllerLukas Müller
115 bronze badges
115 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Declare a setter as a slot in your Diagrama
class and connect your MainWindow
to it:
class Diagrama: public QWidget
Q_OBJECT
...
public slots:
void changeModo() modo = "trafo";
;
In your MainWindow
class:
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better;QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The oldSIGNAL()
andSLOT()
macro crap needs to die.
– Jesper Juhl
Mar 27 at 20:16
@lukas Müller, you have to changeyourDiagramaObject
by the name of your own object.
– Romha Korev
Mar 27 at 20:38
add a comment |
Or use lambda
connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;
Hismodo
variable is in another class. It will not fix his problem, unfortunately.
– Romha Korev
Mar 28 at 8:19
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385533%2fhow-to-change-the-value-of-variables-of-another-class-using-qpushbutton%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Declare a setter as a slot in your Diagrama
class and connect your MainWindow
to it:
class Diagrama: public QWidget
Q_OBJECT
...
public slots:
void changeModo() modo = "trafo";
;
In your MainWindow
class:
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better;QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The oldSIGNAL()
andSLOT()
macro crap needs to die.
– Jesper Juhl
Mar 27 at 20:16
@lukas Müller, you have to changeyourDiagramaObject
by the name of your own object.
– Romha Korev
Mar 27 at 20:38
add a comment |
Declare a setter as a slot in your Diagrama
class and connect your MainWindow
to it:
class Diagrama: public QWidget
Q_OBJECT
...
public slots:
void changeModo() modo = "trafo";
;
In your MainWindow
class:
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better;QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The oldSIGNAL()
andSLOT()
macro crap needs to die.
– Jesper Juhl
Mar 27 at 20:16
@lukas Müller, you have to changeyourDiagramaObject
by the name of your own object.
– Romha Korev
Mar 27 at 20:38
add a comment |
Declare a setter as a slot in your Diagrama
class and connect your MainWindow
to it:
class Diagrama: public QWidget
Q_OBJECT
...
public slots:
void changeModo() modo = "trafo";
;
In your MainWindow
class:
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
Declare a setter as a slot in your Diagrama
class and connect your MainWindow
to it:
class Diagrama: public QWidget
Q_OBJECT
...
public slots:
void changeModo() modo = "trafo";
;
In your MainWindow
class:
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
answered Mar 27 at 20:07
Romha KorevRomha Korev
4,5452 gold badges16 silver badges28 bronze badges
4,5452 gold badges16 silver badges28 bronze badges
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better;QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The oldSIGNAL()
andSLOT()
macro crap needs to die.
– Jesper Juhl
Mar 27 at 20:16
@lukas Müller, you have to changeyourDiagramaObject
by the name of your own object.
– Romha Korev
Mar 27 at 20:38
add a comment |
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better;QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The oldSIGNAL()
andSLOT()
macro crap needs to die.
– Jesper Juhl
Mar 27 at 20:16
@lukas Müller, you have to changeyourDiagramaObject
by the name of your own object.
– Romha Korev
Mar 27 at 20:38
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
it says that is not declared in this scope :(
– Lukas Müller
Mar 27 at 20:14
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better; QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The old SIGNAL()
and SLOT()
macro crap needs to die.– Jesper Juhl
Mar 27 at 20:16
QObject::connect(linha_button, SIGNAL (clicked()), yourDiagramaObject, SLOT(changeModo()));
- better; QObject::connect(linha_button, &QPushButton::clicked, yourDiagramaObject, &Diagrama::changeModo);
- will be checked at compile time, not run time and will be faster since it does not involve a bunch of nasty string comparisons (which the old-style macros cause). Use the new compile time checked, member function pointer based, syntax, please. The old SIGNAL()
and SLOT()
macro crap needs to die.– Jesper Juhl
Mar 27 at 20:16
@lukas Müller, you have to change
yourDiagramaObject
by the name of your own object.– Romha Korev
Mar 27 at 20:38
@lukas Müller, you have to change
yourDiagramaObject
by the name of your own object.– Romha Korev
Mar 27 at 20:38
add a comment |
Or use lambda
connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;
Hismodo
variable is in another class. It will not fix his problem, unfortunately.
– Romha Korev
Mar 28 at 8:19
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
add a comment |
Or use lambda
connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;
Hismodo
variable is in another class. It will not fix his problem, unfortunately.
– Romha Korev
Mar 28 at 8:19
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
add a comment |
Or use lambda
connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;
Or use lambda
connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;
edited Mar 27 at 22:35
eyllanesc
106k12 gold badges38 silver badges71 bronze badges
106k12 gold badges38 silver badges71 bronze badges
answered Mar 27 at 22:33
ArtmeticArtmetic
3252 silver badges8 bronze badges
3252 silver badges8 bronze badges
Hismodo
variable is in another class. It will not fix his problem, unfortunately.
– Romha Korev
Mar 28 at 8:19
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
add a comment |
Hismodo
variable is in another class. It will not fix his problem, unfortunately.
– Romha Korev
Mar 28 at 8:19
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
His
modo
variable is in another class. It will not fix his problem, unfortunately.– Romha Korev
Mar 28 at 8:19
His
modo
variable is in another class. It will not fix his problem, unfortunately.– Romha Korev
Mar 28 at 8:19
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
if it is static maybe AnotherClass::modo in this case Diagrama::modo connect(linha_button,&QPushButton::clicked,[this]() Diagrama::modo = "trafo"; ) ;
– Artmetic
Mar 29 at 10:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385533%2fhow-to-change-the-value-of-variables-of-another-class-using-qpushbutton%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown