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. SIGNAL AND SLOTS

SIGNAL AND SLOTS

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 527 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.
  • A Offline
    A Offline
    AlexandruToma
    wrote on last edited by AlexandruToma
    #1

    Hello, I have a problem and I don't understand why.
    Until now I had only one window(main), and when I added new window and I move some components because in the main where too many, signal and slots stop working. Was everything fine in main, same code in other class(new window) which is printed into a stackedWidget from centralwidget, doesn't work.

      // connect textChange signal with TextChange slot to change height of chat line
      connect(ui.mChatLine, SIGNAL(textChanged()), this, SLOT(TextChanged()));
      // connect user selection signal with UserChange slot to chat view
      connect(ui.mUserList, SIGNAL(clicked(QModelIndex)), this, SLOT(UserChanged(QModelIndex)));
    
    Pl45m4P JonBJ 2 Replies Last reply
    0
    • A AlexandruToma

      @J-Hilk Screenshot (5).png
      Do my new ui have mChatLine and mUserList if I see them here?

      I dont try to acces ui elements from another class. I try to receive an signal from current class ui into the current class slot.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #8

      @AlexandruToma

      If your new class has a chatView, a chatLine and the slots UserChanged() + TextChanged() it should work.
      Re-run qmake and see if it works.

      @AlexandruToma said in SIGNAL AND SLOTS:

      Do my new ui have mChatLine and mUserList if I see them here?

      btw: Not everything what IntelliSense suggests is a good idea.
      How do you design your ui? With QtDesigner?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      A 1 Reply Last reply
      0
      • A AlexandruToma

        Hello, I have a problem and I don't understand why.
        Until now I had only one window(main), and when I added new window and I move some components because in the main where too many, signal and slots stop working. Was everything fine in main, same code in other class(new window) which is printed into a stackedWidget from centralwidget, doesn't work.

          // connect textChange signal with TextChange slot to change height of chat line
          connect(ui.mChatLine, SIGNAL(textChanged()), this, SLOT(TextChanged()));
          // connect user selection signal with UserChange slot to chat view
          connect(ui.mUserList, SIGNAL(clicked(QModelIndex)), this, SLOT(UserChanged(QModelIndex)));
        
        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        @AlexandruToma said in SIGNAL AND SLOTS:

        I move some components because in the main where too many, signal and slots stop working

        "Moved" in which way? You cant just take code from one class to another, especially when the code references ui elements.
        So how exactly did you move your stuff?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        4
        • A AlexandruToma

          Hello, I have a problem and I don't understand why.
          Until now I had only one window(main), and when I added new window and I move some components because in the main where too many, signal and slots stop working. Was everything fine in main, same code in other class(new window) which is printed into a stackedWidget from centralwidget, doesn't work.

            // connect textChange signal with TextChange slot to change height of chat line
            connect(ui.mChatLine, SIGNAL(textChanged()), this, SLOT(TextChanged()));
            // connect user selection signal with UserChange slot to chat view
            connect(ui.mUserList, SIGNAL(clicked(QModelIndex)), this, SLOT(UserChanged(QModelIndex)));
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #3

          @AlexandruToma
          As @Pl45m4 says. And if you used New Signal Slot Syntax you would have a much better chance of spotting mistakes/getting this right, instead of guesswork....

          1 Reply Last reply
          3
          • A Offline
            A Offline
            AlexandruToma
            wrote on last edited by
            #4

            I moved (ctrl+x) all components with their implementation from centralwidget(QMainWindow) into other window. I dont have errors, it s all fine, just doesn't call that UserChanged or TextChanged slots anymore

            J.HilkJ Pl45m4P 2 Replies Last reply
            0
            • A AlexandruToma

              I moved (ctrl+x) all components with their implementation from centralwidget(QMainWindow) into other window. I dont have errors, it s all fine, just doesn't call that UserChanged or TextChanged slots anymore

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by J.Hilk
              #5

              @AlexandruToma thats the point, would you use the new signal and slot syntax, that @JonB linked, you would have compile time errors and not runtime silent fails.

              Copy pasted, huh,
              I'm almost certain your new ui doesn't have a mChatLine or mUserList component in it.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              A 1 Reply Last reply
              4
              • A AlexandruToma

                I moved (ctrl+x) all components with their implementation from centralwidget(QMainWindow) into other window. I dont have errors, it s all fine, just doesn't call that UserChanged or TextChanged slots anymore

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #6

                @AlexandruToma

                Dont try to access ui elements from another class in your new class. It wont work.
                If you need to change something, send a signal to the ui-"owner" class and let the same class change its ui.

                (Send signal from newWindow to your mainWindow and keep the code, you've copied, there)


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                1
                • J.HilkJ J.Hilk

                  @AlexandruToma thats the point, would you use the new signal and slot syntax, that @JonB linked, you would have compile time errors and not runtime silent fails.

                  Copy pasted, huh,
                  I'm almost certain your new ui doesn't have a mChatLine or mUserList component in it.

                  A Offline
                  A Offline
                  AlexandruToma
                  wrote on last edited by
                  #7

                  @J-Hilk Screenshot (5).png
                  Do my new ui have mChatLine and mUserList if I see them here?

                  I dont try to acces ui elements from another class. I try to receive an signal from current class ui into the current class slot.

                  Pl45m4P 1 Reply Last reply
                  0
                  • A AlexandruToma

                    @J-Hilk Screenshot (5).png
                    Do my new ui have mChatLine and mUserList if I see them here?

                    I dont try to acces ui elements from another class. I try to receive an signal from current class ui into the current class slot.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #8

                    @AlexandruToma

                    If your new class has a chatView, a chatLine and the slots UserChanged() + TextChanged() it should work.
                    Re-run qmake and see if it works.

                    @AlexandruToma said in SIGNAL AND SLOTS:

                    Do my new ui have mChatLine and mUserList if I see them here?

                    btw: Not everything what IntelliSense suggests is a good idea.
                    How do you design your ui? With QtDesigner?


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    A 1 Reply Last reply
                    0
                    • Pl45m4P Pl45m4

                      @AlexandruToma

                      If your new class has a chatView, a chatLine and the slots UserChanged() + TextChanged() it should work.
                      Re-run qmake and see if it works.

                      @AlexandruToma said in SIGNAL AND SLOTS:

                      Do my new ui have mChatLine and mUserList if I see them here?

                      btw: Not everything what IntelliSense suggests is a good idea.
                      How do you design your ui? With QtDesigner?

                      A Offline
                      A Offline
                      AlexandruToma
                      wrote on last edited by AlexandruToma
                      #9

                      @Pl45m4 Thank you for you time. The problem was that I forgot to write this line of code

                      public slots:
                      

                      above slots in my new class header file.

                      @J-Hilk said in SIGNAL AND SLOTS:

                      I'm almost certain your new ui doesn't have a mChatLine or mUserList component in it.

                      If I already have all ui components created and styled in one window, it s like a reuse of code, I didn't copy/paste something from web, was my code and I knew what I am doing, when I move all ui components. I just miss that line because in c++ I didn't use that line.
                      You were not trying to help me here, just make fun of me as i copy and paste code. I understand there are many people doing this, but it s not fair to treat all of us like that.
                      Have a good day sir.

                      J.HilkJ 1 Reply Last reply
                      0
                      • A AlexandruToma

                        @Pl45m4 Thank you for you time. The problem was that I forgot to write this line of code

                        public slots:
                        

                        above slots in my new class header file.

                        @J-Hilk said in SIGNAL AND SLOTS:

                        I'm almost certain your new ui doesn't have a mChatLine or mUserList component in it.

                        If I already have all ui components created and styled in one window, it s like a reuse of code, I didn't copy/paste something from web, was my code and I knew what I am doing, when I move all ui components. I just miss that line because in c++ I didn't use that line.
                        You were not trying to help me here, just make fun of me as i copy and paste code. I understand there are many people doing this, but it s not fair to treat all of us like that.
                        Have a good day sir.

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #10

                        @AlexandruToma
                        first of, I'm glad that you were able to solve your problem, and also thanks for sharing the answer, not something everyone does.

                        If I already have all ui components created and styled in one window, it s like a reuse of code, I didn't copy/paste something from web, was my code and I knew what I am doing, when I move all ui components. I just miss that line because in c++ I didn't use that line.
                        You were not trying to help me here, just make fun of me as i copy and paste code. I understand there are many people doing this, but it s not fair to treat all of us like that.

                        to address this: I never said, nor assumed you copied anything from the internet.

                        you said:

                        when I added new window ... signal and slots stop working

                        and on the question

                        "Moved" in which way?

                        you answered:

                        I moved (ctrl+x) all components with their implementation from centralwidget(QMainWindow) into other window.

                        That plus the actual connect call, is all the information we have to go on with. That is not a lot of information. For example had you posted more code of your class in the opening post, @Pl45m4 or @JonB would have easily spotted the missing slots macro

                        Which by the way is a copy and paste error on your part.
                        And, had you, like we suggested, used the new Qt5 Signal/Slot syntax the problem would have gone away, as it does not require the slots macro any longer.

                        Btw, the Qt4 connect statement you used, should have provided the following message during runtime:

                        QObject::connect: No such slot Mainview::TextChanged() in ....

                        which would have been nice to know as well, as it would have made the error obvious.

                        If anything, take this with you:

                        • Don't be discouraged to ask for or provide other in this forum with help.
                        • If you ask a question, provide as much information as possible, ideally a code example or even better, a minimal compileable example. The more the better!
                        • treat warnings as errors (-Werror)
                        • Change over to the new signal/slot syntax, it makes life easier
                        • Think positive 😄

                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        4

                        • Login

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