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. Custum signal in QDialog does not launch a slot in another class
Qt 6.11 is out! See what's new in the release blog

Custum signal in QDialog does not launch a slot in another class

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 5.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have three class:

    1. class A is the main class.
    2. class B inherits from QWidget.
    3. class C inherits from QDialog.

    In the C class there is a QTableWidget ( QTableWidget* tableShape;) and custom slot (void saveTableValue(int r,int c);) and signal (void load();). The saveTableValue slot is called by B class when the user changes a cell (by the signal cellChanged(int,int);). When the saveTableValue slot is executed another signal (void load();) in C class is emitted and calls the custom slot void reloadIfGeometryChanged(); in A class.

    The problem is that that slot void reloadIfGeometryChanged(); (*****) in A class is not executed even though the signal void load(); is emitted (I tested it with a slot in the same class (C) ).

    Here part of my code:

    class A.h

    @class Main_newUI : public QMainWindow
    {
    Q_OBJECT

    public:
    Main_newUI(QString pathPj, QWidget *parent = 0);
    ~Main_newUI();

    // Geometry Docks
    Geometry_UI        *geometryDocks;                                 //!< Create and manage geometry docks
    ShapeDialog        *profileDialog;
    

    public slots:

    void reloadIfGeometryChanged();
    

    };
    }

    #endif // MAIN_NEWUI_H
    @

    class A.cpp

    @Main_newUI::Main_newUI(QString pathPj, QWidget *parent)
    : QMainWindow(parent)
    {

    geometryDocks = new Geometry_UI(...);
    
    profileDialog = geometryDocks->profDialog;
    
    connect(profileDialog, SIGNAL(load()), this, SLOT(reloadIfGeometryChanged())); (******DOES NOT WORK!!!)
    

    }

    void Main_newUI::reloadIfGeometryChanged(){
    .......
    }
    @

    class B.h

    @class Geometry_UI : public QWidget
    {
    Q_OBJECT
    public:
    explicit Geometry_UI(...);
    ~Geometry_UI();

    QMainWindow   *mainWindow;
    
    ShapeDialog* profDialog;
    

    };
    }

    #endif // GEOMETRY_UI_H
    @

    class B.cpp

    @Geometry_UI::Geometry_UI(...)
    {
    profDialog = new ShapeDialog();
    }

    void Geometry_UI::update(){
    QTableWidget* profileTable = new QTableWidget(profDialog);
    profDialog = new ShapeDialog(profBtn, profileTable);
    connect(profileTable, SIGNAL(cellChanged(int,int)), profDialog, SLOT(saveTableValue(int,int)));
    }
    @

    class C.h

    @class ShapeDialog : public QDialog {

    Q_OBJECT
    

    public:
    ShapeDialog(QWidget* parent = 0, QTableWidget* tableSh = NULL);

    ~ShapeDialog();
    
    QTableWidget*   tableShape;
    

    public slots:
    void saveTableValue(int r,int c);

    signals:
    void load();
    };

    #endif // SHAPEDIALOG_H
    @

    class C.cpp

    @ShapeDialog::ShapeDialog(QWidget* parent, QTableWidget* tableSh)
    : QDialog(parent),
    tableShape(tableSh){}

    void ShapeDialog::saveTableValue(int r,int c){

    ....
    
    emit load();
    

    }
    @

    Can someone help me please?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      check the return value of the connect statement

      check the output on the console

      this gives you a pretty clear reason whats going wrong.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thank you raven-worx, I have checked if the connect statement works and it does (the bool is 1) and I ve printed something in the saveTableValue slot and it works also....

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          when the connect() returns true the connection is fine and everything will work.
          So there must be something else... the posted code looks good.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            exactely I cant find out what's wrong. I tried to emit the same signal in B class and connected in the A class, and it works! the only difference I see is that the case that doesn't work is a QDialog!! what's wrong with that?!

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              should also work. even if you call QDialog::exec() to show it.
              Did you try a full rebuild of your project?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                What do you mean with "even if you call QDialog::exec() to show it."?

                yes I tried twice to rebuild...nothing

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  [quote author="valeSimu" date="1422369443"]What do you mean with "even if you call QDialog::exec() to show it."?[/quote]

                  because QDialog::exec() opens a new event-loop. Nevermind.

                  I don't have any more hints for you sry.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andreyc
                    wrote on last edited by
                    #9

                    Could you show where do you show or exec profDialog.
                    Is profHullDialog related to profDialog?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andreyc
                      wrote on last edited by
                      #10

                      Another question.
                      How many times do you call Geometry_UI::update()?
                      In current implementation you create new table on each update.

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #11
                        • in class B.cpp show the profDialog in thi way

                        @connect(profBtn, SIGNAL(clicked()), profDialog, SLOT(show()));@

                        • and yes proHullDialog and profDialog are the same, I corrected it, thx

                        • yes the table is created for every element it finds in a list, for this reason update is called many times

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andreyc
                          wrote on last edited by
                          #12

                          The connect in MainWindow ctor uses a Geomentry_UI::profDialog pointer allocated in Geometry_UI ctor.
                          In Geometry_UI::update() you lose that pointer and allocate another and you use that new pointer to connect with a table widget.
                          You need to rethink the connections and allocations.

                          @
                          Main_newUI::Main_newUI(QString pathPj, QWidget *parent)
                          : QMainWindow(parent)
                          {
                          geometryDocks = new Geometry_UI(...); // Creates a pointer to profDialog
                          profileDialog = geometryDocks->profDialog;
                          connect(profileDialog, SIGNAL(load()), this, SLOT(reloadIfGeometryChanged())); // Uses that pointer to make a connection.
                          }

                          void Geometry_UI::update()
                          {
                          QTableWidget* profileTable = new QTableWidget(profDialog);
                          profDialog = new ShapeDialog(profBtn, profileTable); // The pointer previously allocated in ctor is lost here.
                          connect(profileTable, SIGNAL(cellChanged(int,int)), profDialog, SLOT(saveTableValue(int,int))); // profileTable is connected to new profDialog that is not connected with MainWindow.
                          }

                          @

                          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