Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Please help me with easy problems. How to connect(//)

Please help me with easy problems. How to connect(//)

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    freelife
    wrote on last edited by
    #1

    Please help to russian newcomer)
    My english is not enough to understand documentation very well.
    I have 2 problems.
    1)
    This coonect doesn't work:
    connect( &error, SIGNAL( isVisible(bool) ), this, SLOT( setDisabled(bool) ));
    error is static member of class(this)
    I need to do this rulls:
    error.hide()<=>this.Enabled()
    error.show()<=>this.Disabled()
    2)
    How to connect Enter key pressing(in this) with changing focus to next object, like Tab key does?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arnolddumas
      wrote on last edited by
      #2

      The common connect syntax is :

      @QObject::connect(senderObject, SIGNAL(mySignal()), receiverObject, SLOT(mySlot()));@

      Where :

      • senderObject is a pointer to a QObject, commonly to a QWidget, for instance QPushButton.
      • mySignal() is the signal you're listening to, for example clicked() signal for a QPushButton.
      • receiverObject is a pointer to a QObject that has the slot you'd like to call.
      • mySlot() is the slot you want to call.

      Example :

      @MyMainWindow::MyMainWindow()
      {
      QPushButton* myButton = new QPushButton("Close");
      QObject::connect(myButton, SIGNAL(clicked()), this, SLOT(close()));
      }@

      Considering you have a class called MyMainWindow that inherits from QMainWindow. So you create a QPushButton, and when someone click on it, the window will be closed. Because the slot called close() of the QMainWindow will be call.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        freelife
        wrote on last edited by
        #3

        Yes, I know it.
        Sorry I did't see "Code key" here, and my post is't correct.

        This is problem connect:
        @/*Need this:
        error.hide()<=>OboiCalc.Enabled()
        error.show()<=>OboiCalc.Disabled()
        */@
        @OboiCalc::OboiCalc(QWidget *parent):QWidget(parent)
        {
        //....
        connect(&error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
        //...
        }@
        @
        class OboiCalc : public QWidget,
        {
        private:
        QDialog error;
        //...
        }
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          arnolddumas
          wrote on last edited by
          #4

          Ok, now I see your problem :

          @
          OboiCalc::OboiCalc(QWidget* parent) : QWidget(parent)
          {
          connect(error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
          }
          @

          error should be a pointer to a QDialog.

          @
          class OboiCalc : public QWidget
          {
          private :

          QDialog* error;
          

          }
          @

          This should work fine now

          1 Reply Last reply
          0
          • F Offline
            F Offline
            freelife
            wrote on last edited by
            #5

            but I use here "&", as in another connects, which work very well.
            @connect(error.pushButton, SIGNAL(clicked()), &error, SLOT(hide()));
            connect(error.pushButton_2, SIGNAL(clicked()), &error, SLOT(hide ()));@
            It is compiled, but SLOT(setDisabled) of OboiCalc doesn't work.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              freelife
              wrote on last edited by
              #6

              I made error as a pointer to a QDialog and added -> to all methods, but program exited with code -1073741819.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SetBetterPass
                wrote on last edited by
                #7

                Which slot doesn't work?
                You should put something like qDebug()<<"in slot"; at first line of slot (don't forget include QDebug) to see if the problem is with connect or in slot code, if you won't get "in slot" in application output after you call slot the problem is with connecting. Try it and if you won't find the problem by yourself post code.
                And to your error, have you created the object? Add this line to your code if not: @ error=new QDialog(this);@ where you need to create the dialog.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  freelife
                  wrote on last edited by
                  #8

                  "This is sourse":https://docviewer.yandex.ru/?url=ya-disk:///disk/Oboi.rar&name=Oboi.rar&c=5156c2610790
                  click at" Скачать оригинал " on the top.
                  Then if you click at first button("Счет") the window chould setDisable, but it shouldn't. This is problem.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SetBetterPass
                    wrote on last edited by
                    #9

                    please post your code here(just the part with issue), I can't speak/read Russian well and it wants me to log in to see the code, I am not going to create account^^

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      freelife
                      wrote on last edited by
                      #10

                      Sorry I did't know, what you must have accaunt to download)
                      Look at calc.cpp.
                      @//calc.h
                      #ifndef CALC_H
                      #define CALC_H
                      #include <QDialog>
                      #include "ui_OboiCalc.h"
                      #include <Error.h>

                      class OboiCalc : public QWidget, public Ui::OboiCalc
                      {
                      Q_OBJECT
                      public:
                      OboiCalc(QWidget *parent = 0);
                      private:
                      Error1 error;
                      protected slots:
                      void setValue();
                      void clearCalc();
                      };

                      #endif // CALC_H
                      @
                      @//Error.h
                      #ifndef ERROR_H
                      #define ERROR_H
                      #include <QDialog>
                      #include "ui_Error1.h"

                      class Error1 : public QDialog, public Ui::Error1
                      {
                      Q_OBJECT
                      public:
                      Error1(QWidget parent = 0);
                      };
                      #endif // ERROR_H
                      @
                      @//calc.cpp
                      #include <QtGui>
                      #include "Calc.h"
                      #include <Error.h>
                      OboiCalc::OboiCalc(QWidget parent):QWidget(parent)
                      {
                      setupUi(this);
                      spinBox2_3->setDisabled(true);
                      //
                      **********************************
                      connect(&error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));//This connect doesn't work =(
                      //************************************
                      connect(buttonOk, SIGNAL(clicked()), this, SLOT(setValue()));
                      connect(buttonClear, SIGNAL(clicked()), this, SLOT(clearCalc()));
                      connect(error.pushButton, SIGNAL(clicked()), &error, SLOT(hide()));
                      connect(error.pushButton_2, SIGNAL(clicked()), &error, SLOT(hide ()));
                      connect(error.pushButton_2, SIGNAL(clicked()), this, SLOT(clearCalc()));
                      connect(checkBox, SIGNAL(clicked(bool)), spinBox2_3, SLOT(setEnabled(bool)));

                      }
                      void OboiCalc::clearCalc()
                      {
                      //something
                      }
                      void OboiCalc::setValue()//вывод
                      {
                      //something
                      error.show();

                      }
                      @
                      @//error.cpp
                      #include <QtGui>
                      #include <Calc.h>
                      #include <Error.h>
                      Error1::Error1(QWidget *parent): QDialog(parent)
                      {
                      setupUi(this);

                      }
                      @

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SetBetterPass
                        wrote on last edited by
                        #11

                        actually you haven't created object error so you cant connect it.
                        You should connect these 2 buttons in error.cpp in constructor, so from this:
                        @
                        connect(error.pushButton, SIGNAL(clicked()), &error, SLOT(hide()));
                        connect(error.pushButton_2, SIGNAL(clicked()), &error, SLOT(hide ()));
                        @
                        make this: @
                        Error1::Error1(QWidget *parent): QDialog(parent)
                        {
                        setupUi(this);
                        connect(pushButton, SIGNAL(clicked()), this, SLOT(hide()));
                        connect(pushButton_2, SIGNAL(clicked()), this, SLOT(hide ()));

                        }@
                        Don't forget create slots before debugging (at least empty) or you get errors.

                        and to connect these 2:
                        @
                        connect(error.pushButton_2, SIGNAL(clicked()), this, SLOT(clearCalc()));
                        connect(&error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
                        @
                        you have to have created object:
                        @
                        //in constructor or somewhere:
                        connect(something,SIGNAL(someSignal()),this,SLOT(errorMessage()));
                        @
                        make slot that creates error message
                        @
                        void OboiCalc::errorMessage(){
                        Error1* error = new Error1(this);
                        connect(error->pushButton_2, SIGNAL(clicked()), this, SLOT(clearCalc()));
                        connect(error, SIGNAL(isVisible(bool)), this, SLOT(setDisabled(bool)));
                        error->show();
                        }
                        @

                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          freelife
                          wrote on last edited by
                          #12

                          Thank you! I understood)

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SetBetterPass
                            wrote on last edited by
                            #13

                            No problem, ask more if you there is something you need to help with, otherwise mark thread [Solved] (edit post and add [Solved] to title). :)

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved