Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with connect
Qt 6.12 LTS is out! See what's new in the release blog

Problem with connect

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 2.0k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vin212
    wrote on last edited by vin212
    #1

    Hello !

    I have au problem, i would like create an signal for my progressbar for this, i use connect with a slot i create and signal (i create olso) but, whene i launch ma program, it's compile but, i my application crash during the signal was emit. I lauche with debug but, i have a segmentation default. I check the value return by the fonction connect and every connection was in "true".

    Do you have any solution ? Or an other possibility for make this ? (i use signal beaucause if i call imediatly the function, i have an loop for the include)

    my code :

    "barrecalcul.h":

    #ifndef BARRECALCUL_H
    #define BARRECALCUL_H
    
    //#include "mainwindowstraitement.h"
    #include "ui_mainwindowtracage.h"
    
    #include "logger.h"
    
    class BarreCalcul : public QMainWindow
    {
        Q_OBJECT
    public:
       BarreCalcul(Logger *log);
       //BarreCalcul(MainWindowsTraitement *affichage);
    private:
       //MainWindowsTraitement *affichage;
       bool premierFois;
       Logger *log;
    public :
       void changePourcentage(int pourcentage);
    
    signals:
       void signalAfficherBarreCalcul();
       void signalChangerPourcentage(int pourcentage);
       void signalMasquerBarreCalcul();
    };
    
    #endif // BARRECALCUL_H
    

    barrecaclul.cpp:

    #include "header\barrecalcul.h"
    
    BarreCalcul::BarreCalcul(Logger *log)
    {
        premierFois = true;
        this->log = log;
    }
    
    void BarreCalcul::changePourcentage(int pourcentage)
    {
    
        //log->WriteLog((char*)"Je change de pourcentage",Logger::Error);
        printf("Je change de pourcentage");
        if (premierFois == true && pourcentage < 2048 && pourcentage > 0)
        {
            //log->WriteLog((char*)"J affiche",Logger::Warning);
            emit signalAfficherBarreCalcul();
            emit signalChangerPourcentage(pourcentage);
            printf("J affiche");
        }
        else if (pourcentage < 2048 && pourcentage > 0)
        {
            //log->WriteLog((char*)"Je change",Logger::Warning);
            emit signalChangerPourcentage(pourcentage);
            printf("Je change");
        }
        else
        {
            //log->WriteLog((char*)"Je masque",Logger::Warning);
            emit signalMasquerBarreCalcul();
        }
    }
    
    

    and the second class :

    mainWindowaction.h :

    /**
     * @file mainwindowsaction.h
     * @author 
     * @date
     * @brief class permetant de gérer tout les interaction sur l'interface
    */
    
    #ifndef MAINWINDOWSACTION_H
    #define MAINWINDOWSACTION_H
    
    #include "mainwindowsaffichageMe.h"
    #include "mainwindowtracage.h"
    #include "mainwindowstraitement.h"
    
    #include "ui_mainwindowtracage.h"
    
    #include "barrecalcul.h"
    
    
    
    class MainWindowsAction : public QMainWindow
    {
        Q_OBJECT
        public:
            MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsTraitement *traitement);
            //~MainWindowsActionMe();
        public slots:                                //fonction qui peut être appeler lors d'une action de l'utilisateur sur la fenête
    
            /**
             * @brief MainWindow::OuvrirFenetreDialogRecupFichier fonction qui permet de lancer la pop-up et de récupérer le nom du fichier selectionner
             */
            void OuvrirFenetreDialogRecupFichier();
    
            /**
             * @brief actionBoutonVisualiser
             * @todo faire le calcul du parcour du robot et l'afficher
             */
            void actionBoutonVisualiser();
    
            /**
             * @brief checkValOrientation vérifie si la valeur de l'orientation choisi est bien valide
             */
            void actionChangmentValOrientation();
    
            /**
             * @brief checkValInterligne verifie si l'intersaction entre chaque ligne est bien valdide
             */
            void actionChangmentValInterligne();
    
            /**
             * @brief actionBoutonValiderParcelle fonction qui s'active lorsque l'on appuie sur le bouton "valider" vérifie si une parcelle est bien saisi
             */
            void actionBoutonValiderParcelle();
    
            /**
             * @brief actionBoutonTelecharger permet d'ouvrir une pop up et de lancer le téléchargement du fichier de sortie
             */
            void actionBoutonTelecharger();
    
        private:
    
            /**
             * @brief window un pointeur sur la class  MainWindowTracage de la fenetre principale avec toute les données de la fenetre
             */
            MainWindowTracage *window;
    
            /**
             * @brief affichage un pointeur sur la class MainWindowsAffichageMe qui gère tout les affichage de la fenetre
             */
            MainWindowsAffichageMe *affichage;
    
            /**
             * @brief traitement un pointeur sur la class MainWindowsTraitement qui gère tout les traitement lier à la fenetre
             */
            MainWindowsTraitement *traitement;
    
    
        public slots :
             void masquerBarreCalcul();
    
             void afficherBarreCalcul();
    
             void changerPourcentage(int pourcentage);
    
    
    };
    
    
    
    
    
    #endif // MAINWINDOWSACTION_H
    
    

    mainwindowsAction.h

    
    #include "header\mainwindowsaction.h"
    
    MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsTraitement *traitement)
    {
        this->window = window;
        this->affichage = affichage;
        this->traitement = traitement;
    
        char Message[64];
    
    
    
        bool a = connect(traitement->barreCalcul,&BarreCalcul::signalAfficherBarreCalcul,this, &MainWindowsAction::afficherBarreCalcul);
    
        sprintf(Message,"connect 1 :%d",a);
        window->log->WriteLog(Message,Logger::Error);
    
        a = connect(traitement->barreCalcul,&BarreCalcul::signalMasquerBarreCalcul,this, &MainWindowsAction::masquerBarreCalcul);
    
        sprintf(Message,"connect 2 :%d",a);
        window->log->WriteLog(Message,Logger::Error);
    
        a = connect(traitement->barreCalcul,&BarreCalcul::signalChangerPourcentage,this, &MainWindowsAction::changerPourcentage);
    
    
        sprintf(Message,"connect 3 :%d",a);
        window->log->WriteLog(Message,Logger::Error);
    
    
        connect(window->ui->BoutonSelectionnerParcelle, &QPushButton::clicked,this, &MainWindowsAction::OuvrirFenetreDialogRecupFichier);
        connect(window->ui->BoutonVisualiser, &QPushButton::clicked,this, &MainWindowsAction::actionBoutonVisualiser);
        connect(window->ui->valOrientation, &QComboBox::currentTextChanged,this, &MainWindowsAction::actionChangmentValOrientation);
        connect(window->ui->valInterligne, &QComboBox::currentTextChanged,this, &MainWindowsAction::actionChangmentValInterligne);
        connect(window->ui->boutonValiderParcelle, &QPushButton::clicked,this, &MainWindowsAction::actionBoutonValiderParcelle);
        connect(window->ui->boutonTelecharger, &QPushButton::clicked,this,&MainWindowsAction::actionBoutonTelecharger);
    }
    
    void MainWindowsAction::OuvrirFenetreDialogRecupFichier()
    {
        traitement->traiterFenetreDialogFichier();
    
    }
    
    void MainWindowsAction::actionBoutonVisualiser()
    {
        traitement->traiterVisualisation();
    
    }
    
    void MainWindowsAction::actionChangmentValOrientation()
    {
        traitement->checkValOrientation();
    }
    
    void MainWindowsAction::actionChangmentValInterligne()
    {
        traitement->checkValInterligne();
    }
    
    void MainWindowsAction::actionBoutonValiderParcelle()
    {
        traitement->traiterValiderParcelle();
    }
    
    void MainWindowsAction::actionBoutonTelecharger()
    {
        traitement->traitementTelechargement();
    }
    
    void MainWindowsAction::masquerBarreCalcul()
    {
        affichage->masquerBarreCalcul();
    }
    
    void MainWindowsAction::afficherBarreCalcul()
    {
        affichage->afficherBarreCalcul();
    }
    
    void MainWindowsAction::changerPourcentage(int pourcentage)
    {
        affichage->changerPourcentage(pourcentage);
    }
    
    
    

    thank's for your answer !

    jsulmJ 1 Reply Last reply
    0
    • V vin212

      Hello !

      I have au problem, i would like create an signal for my progressbar for this, i use connect with a slot i create and signal (i create olso) but, whene i launch ma program, it's compile but, i my application crash during the signal was emit. I lauche with debug but, i have a segmentation default. I check the value return by the fonction connect and every connection was in "true".

      Do you have any solution ? Or an other possibility for make this ? (i use signal beaucause if i call imediatly the function, i have an loop for the include)

      my code :

      "barrecalcul.h":

      #ifndef BARRECALCUL_H
      #define BARRECALCUL_H
      
      //#include "mainwindowstraitement.h"
      #include "ui_mainwindowtracage.h"
      
      #include "logger.h"
      
      class BarreCalcul : public QMainWindow
      {
          Q_OBJECT
      public:
         BarreCalcul(Logger *log);
         //BarreCalcul(MainWindowsTraitement *affichage);
      private:
         //MainWindowsTraitement *affichage;
         bool premierFois;
         Logger *log;
      public :
         void changePourcentage(int pourcentage);
      
      signals:
         void signalAfficherBarreCalcul();
         void signalChangerPourcentage(int pourcentage);
         void signalMasquerBarreCalcul();
      };
      
      #endif // BARRECALCUL_H
      

      barrecaclul.cpp:

      #include "header\barrecalcul.h"
      
      BarreCalcul::BarreCalcul(Logger *log)
      {
          premierFois = true;
          this->log = log;
      }
      
      void BarreCalcul::changePourcentage(int pourcentage)
      {
      
          //log->WriteLog((char*)"Je change de pourcentage",Logger::Error);
          printf("Je change de pourcentage");
          if (premierFois == true && pourcentage < 2048 && pourcentage > 0)
          {
              //log->WriteLog((char*)"J affiche",Logger::Warning);
              emit signalAfficherBarreCalcul();
              emit signalChangerPourcentage(pourcentage);
              printf("J affiche");
          }
          else if (pourcentage < 2048 && pourcentage > 0)
          {
              //log->WriteLog((char*)"Je change",Logger::Warning);
              emit signalChangerPourcentage(pourcentage);
              printf("Je change");
          }
          else
          {
              //log->WriteLog((char*)"Je masque",Logger::Warning);
              emit signalMasquerBarreCalcul();
          }
      }
      
      

      and the second class :

      mainWindowaction.h :

      /**
       * @file mainwindowsaction.h
       * @author 
       * @date
       * @brief class permetant de gérer tout les interaction sur l'interface
      */
      
      #ifndef MAINWINDOWSACTION_H
      #define MAINWINDOWSACTION_H
      
      #include "mainwindowsaffichageMe.h"
      #include "mainwindowtracage.h"
      #include "mainwindowstraitement.h"
      
      #include "ui_mainwindowtracage.h"
      
      #include "barrecalcul.h"
      
      
      
      class MainWindowsAction : public QMainWindow
      {
          Q_OBJECT
          public:
              MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsTraitement *traitement);
              //~MainWindowsActionMe();
          public slots:                                //fonction qui peut être appeler lors d'une action de l'utilisateur sur la fenête
      
              /**
               * @brief MainWindow::OuvrirFenetreDialogRecupFichier fonction qui permet de lancer la pop-up et de récupérer le nom du fichier selectionner
               */
              void OuvrirFenetreDialogRecupFichier();
      
              /**
               * @brief actionBoutonVisualiser
               * @todo faire le calcul du parcour du robot et l'afficher
               */
              void actionBoutonVisualiser();
      
              /**
               * @brief checkValOrientation vérifie si la valeur de l'orientation choisi est bien valide
               */
              void actionChangmentValOrientation();
      
              /**
               * @brief checkValInterligne verifie si l'intersaction entre chaque ligne est bien valdide
               */
              void actionChangmentValInterligne();
      
              /**
               * @brief actionBoutonValiderParcelle fonction qui s'active lorsque l'on appuie sur le bouton "valider" vérifie si une parcelle est bien saisi
               */
              void actionBoutonValiderParcelle();
      
              /**
               * @brief actionBoutonTelecharger permet d'ouvrir une pop up et de lancer le téléchargement du fichier de sortie
               */
              void actionBoutonTelecharger();
      
          private:
      
              /**
               * @brief window un pointeur sur la class  MainWindowTracage de la fenetre principale avec toute les données de la fenetre
               */
              MainWindowTracage *window;
      
              /**
               * @brief affichage un pointeur sur la class MainWindowsAffichageMe qui gère tout les affichage de la fenetre
               */
              MainWindowsAffichageMe *affichage;
      
              /**
               * @brief traitement un pointeur sur la class MainWindowsTraitement qui gère tout les traitement lier à la fenetre
               */
              MainWindowsTraitement *traitement;
      
      
          public slots :
               void masquerBarreCalcul();
      
               void afficherBarreCalcul();
      
               void changerPourcentage(int pourcentage);
      
      
      };
      
      
      
      
      
      #endif // MAINWINDOWSACTION_H
      
      

      mainwindowsAction.h

      
      #include "header\mainwindowsaction.h"
      
      MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsTraitement *traitement)
      {
          this->window = window;
          this->affichage = affichage;
          this->traitement = traitement;
      
          char Message[64];
      
      
      
          bool a = connect(traitement->barreCalcul,&BarreCalcul::signalAfficherBarreCalcul,this, &MainWindowsAction::afficherBarreCalcul);
      
          sprintf(Message,"connect 1 :%d",a);
          window->log->WriteLog(Message,Logger::Error);
      
          a = connect(traitement->barreCalcul,&BarreCalcul::signalMasquerBarreCalcul,this, &MainWindowsAction::masquerBarreCalcul);
      
          sprintf(Message,"connect 2 :%d",a);
          window->log->WriteLog(Message,Logger::Error);
      
          a = connect(traitement->barreCalcul,&BarreCalcul::signalChangerPourcentage,this, &MainWindowsAction::changerPourcentage);
      
      
          sprintf(Message,"connect 3 :%d",a);
          window->log->WriteLog(Message,Logger::Error);
      
      
          connect(window->ui->BoutonSelectionnerParcelle, &QPushButton::clicked,this, &MainWindowsAction::OuvrirFenetreDialogRecupFichier);
          connect(window->ui->BoutonVisualiser, &QPushButton::clicked,this, &MainWindowsAction::actionBoutonVisualiser);
          connect(window->ui->valOrientation, &QComboBox::currentTextChanged,this, &MainWindowsAction::actionChangmentValOrientation);
          connect(window->ui->valInterligne, &QComboBox::currentTextChanged,this, &MainWindowsAction::actionChangmentValInterligne);
          connect(window->ui->boutonValiderParcelle, &QPushButton::clicked,this, &MainWindowsAction::actionBoutonValiderParcelle);
          connect(window->ui->boutonTelecharger, &QPushButton::clicked,this,&MainWindowsAction::actionBoutonTelecharger);
      }
      
      void MainWindowsAction::OuvrirFenetreDialogRecupFichier()
      {
          traitement->traiterFenetreDialogFichier();
      
      }
      
      void MainWindowsAction::actionBoutonVisualiser()
      {
          traitement->traiterVisualisation();
      
      }
      
      void MainWindowsAction::actionChangmentValOrientation()
      {
          traitement->checkValOrientation();
      }
      
      void MainWindowsAction::actionChangmentValInterligne()
      {
          traitement->checkValInterligne();
      }
      
      void MainWindowsAction::actionBoutonValiderParcelle()
      {
          traitement->traiterValiderParcelle();
      }
      
      void MainWindowsAction::actionBoutonTelecharger()
      {
          traitement->traitementTelechargement();
      }
      
      void MainWindowsAction::masquerBarreCalcul()
      {
          affichage->masquerBarreCalcul();
      }
      
      void MainWindowsAction::afficherBarreCalcul()
      {
          affichage->afficherBarreCalcul();
      }
      
      void MainWindowsAction::changerPourcentage(int pourcentage)
      {
          affichage->changerPourcentage(pourcentage);
      }
      
      
      

      thank's for your answer !

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @vin212 said in Problem with connect:

      I lauche with debug but, i have a segmentation default

      Then you should check the stack trace to see where exactly it happens.
      So, please post the stack trace.
      Did you pass valid pointers here:

      MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsTraitement *traitement)
      {
          this->window = window;
          this->affichage = affichage;
          this->traitement = traitement;
      
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vin212
        wrote on last edited by
        #3

        yes, the pointer was valid, i use the different pointer on other function and it's work before i add the signal/slot.

        yess, i can add the stack but i don't know how ^^'

        jsulmJ 1 Reply Last reply
        0
        • V vin212

          yes, the pointer was valid, i use the different pointer on other function and it's work before i add the signal/slot.

          yess, i can add the stack but i don't know how ^^'

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @vin212 Run your app through debugger. When it crashes you will have the stack trace in debugger view.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vin212
            wrote on last edited by vin212
            #5
                                                                                                                                                                                                                                        
            1   QObjectPrivate::maybeSignalConnected(unsigned int) const                                                                                                                                                     0x68c66828 
            2   void doActivate<false>(QObject *, int, void * *)                                                                                                                                                             0x68d64c16 
            -> 3   BarreCalcul::signalMasquerBarreCalcul                                                                                                                                          moc_barrecalcul.cpp       168 0x40cec0   
            4   BarreCalcul::changePourcentage                                                                                                                                                 barrecalcul.cpp           30  0x401788   
            5   PolygonInfill::DecoupeGrille                                                                                                                                                   polygoninfill.cpp         74  0x406408   
            6   PolygonInfill::lancerCalcul                                                                                                                                                    polygoninfill.cpp         15  0x406245   
            7   MainWindowsTraitement::traiterVisualisation                                                                                                                                    mainwindowstraitement.cpp 117 0x401fed   
            8   MainWindowsAction::actionBoutonVisualiser                                                                                                                                      mainwindowsaction.cpp     46  0x40a596   
            9   QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (MainWindowsAction:: *)()>::call(void (MainWindowsAction:: *)(), MainWindowsAction *, void * *) qobjectdefs_impl.h        152 0x41b5c1   
            10  QtPrivate::FunctionPointer<void (MainWindowsAction:: *)()>::call<QtPrivate::List<>, void>(void (MainWindowsAction:: *)(), MainWindowsAction *, void * *)                       qobjectdefs_impl.h        185 0x41b87e   
            11  QtPrivate::QSlotObject<void (MainWindowsAction:: *)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void * *, bool *)                          qobjectdefs_impl.h        418 0x41b778   
            12  void doActivate<false>(QObject *, int, void * *)                                                                                                                                                             0x68d64fe0 
            13  QAbstractButtonPrivate::emitClicked()                                                                                                                                                                        0x2361d90  
            14  QAbstractButtonPrivate::click()                                                                                                                                                                              0x2363259  
            15  QAbstractButton::mouseReleaseEvent(QMouseEvent *)                                                                                                                                                            0x23633c5  
            16  QWidget::event(QEvent *)                                                                                                                                                                                     0x22b50b1  
            17  QApplicationPrivate::notify_helper(QObject *, QEvent *)                                                                                                                                                      0x2277b2c  
            18  QApplication::notify(QObject *, QEvent *)                                                                                                                                                                    0x227f0f7  
            19  QCoreApplication::sendSpontaneousEvent(QObject *, QEvent *)                                                                                                                                                  0x68c416f9 
            20  QApplicationPrivate::sendMouseEvent(QWidget *, QMouseEvent *, QWidget *, QWidget *, QWidget * *, QPointer<QWidget>&, bool, bool)                                                                             0x227d771  
            ... <plus> 
                                                                                                                                                                                                                             
            

            the debug stop on this line :

            void BarreCalcul::signalAfficherBarreCalcul()
            {
                ->QMetaObject::activate(this, &staticMetaObject, 0, nullptr);
            }
            
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mpergand
              wrote on last edited by mpergand
              #6

              Salut,
              There's probably an invalid object somewhere ...

              MainWindowTracage *window;
              MainWindowsAffichageMe *affichage;
              MainWindowsTraitement *traitement;

              Are you sure all this objects are correctly instantiated ?

              V 1 Reply Last reply
              0
              • M mpergand

                Salut,
                There's probably an invalid object somewhere ...

                MainWindowTracage *window;
                MainWindowsAffichageMe *affichage;
                MainWindowsTraitement *traitement;

                Are you sure all this objects are correctly instantiated ?

                V Offline
                V Offline
                vin212
                wrote on last edited by vin212
                #7

                @mpergand

                Yess, i'm sure, every object was use before the crash. and i initilaze at the first time on the main :

                  MainWindowTracage window(&log);
                
                    MainWindowsAffichageMe affichage (&window);
                    MainWindowsTraitement traitement = MainWindowsTraitement(&window,&affichage);
                    MainWindowsAction action(&window,&affichage,&traitement);
                

                And, when i sub the class "BarreCalcul" my application work and don't crash

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mpergand
                  wrote on last edited by
                  #8

                  @vin212 said in Problem with connect:

                  QMetaObject::activate(this, &staticMetaObject, 0, nullptr);
                  I've never used activate, are you sure that's correct way to use it ?
                  Why not emit a signal instead.

                  V 1 Reply Last reply
                  0
                  • M mpergand

                    @vin212 said in Problem with connect:

                    QMetaObject::activate(this, &staticMetaObject, 0, nullptr);
                    I've never used activate, are you sure that's correct way to use it ?
                    Why not emit a signal instead.

                    V Offline
                    V Offline
                    vin212
                    wrote on last edited by
                    #9

                    @mpergand

                    it's a file generate automatic. I emit a signal with the "emit <function>"

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mpergand
                      wrote on last edited by
                      #10

                      Put a breakpoint the line before the line that crash and inspect the variables in the right panel if there are not some invalid objects.

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        vin212
                        wrote on last edited by vin212
                        #11

                        i fixe my bug ! i create the object barreCalcul on the function but, the object as sub after and the pointer is not valid. I need to creat the object at out of my class for don't crash.

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