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;








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??










share|improve this question
































    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??










    share|improve this question




























      0












      0








      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??










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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

























          2 Answers
          2






          active

          oldest

          votes


















          1















          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()));





          share|improve this answer

























          • 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












          • @lukas Müller, you have to change yourDiagramaObject by the name of your own object.

            – Romha Korev
            Mar 27 at 20:38


















          0















          Or use lambda



          connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;





          share|improve this answer



























          • 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














          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
          );



          );













          draft saved

          draft discarded


















          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









          1















          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()));





          share|improve this answer

























          • 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












          • @lukas Müller, you have to change yourDiagramaObject by the name of your own object.

            – Romha Korev
            Mar 27 at 20:38















          1















          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()));





          share|improve this answer

























          • 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












          • @lukas Müller, you have to change yourDiagramaObject by the name of your own object.

            – Romha Korev
            Mar 27 at 20:38













          1














          1










          1









          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()));





          share|improve this answer













          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()));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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

















          • 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












          • @lukas Müller, you have to change yourDiagramaObject 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













          0















          Or use lambda



          connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;





          share|improve this answer



























          • 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
















          0















          Or use lambda



          connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;





          share|improve this answer



























          • 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














          0














          0










          0









          Or use lambda



          connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;





          share|improve this answer















          Or use lambda



          connect(linha_button,&QPushButton::clicked,[this]() modo = "trafo"; ) ;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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















          • 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


















          • 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

















          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


















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현