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. How to link one class to another??
Qt 6.11 is out! See what's new in the release blog

How to link one class to another??

Scheduled Pinned Locked Moved General and Desktop
21 Posts 2 Posters 14.3k 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.
  • Y Offline
    Y Offline
    YuriQ
    wrote on last edited by
    #12

    You can use signals and slots like this:

    @
    int main( int argc, char *argv[] )
    {
    QApplication app(argc, argv);

    QTextEdit editor1;
    QTextEdit editor2;

    editor1.show();
    editor2.show();

    QObject::connect(&editor1, &QTextEdit::textChanged, &editor2, &QTextEdit::clear);

    return app.exec();
    }
    @

    Every time you edit text in editor1 - editor2 clear it's content.

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      YuriQ
      wrote on last edited by
      #13

      So you can do something like this:

      1. define "playRequest" signal in your controls class
      2. define and implement "onPlayRequest" slot in your screen class
      3. connect them
      4. emit "playRequest" in contols:: play() function
      1 Reply Last reply
      0
      • H Offline
        H Offline
        herculis
        wrote on last edited by
        #14

        I know its a silly question but i dont know much abt this signalsand slots.
        How to define signals and slots.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          YuriQ
          wrote on last edited by
          #15

          Did you read "this article":http://qt-project.org/doc/qt-5/signalsandslots.html?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            herculis
            wrote on last edited by
            #16

            Ya i read the article but How to define it can you ply give me one short example so that i will know how they are comunicating in different class

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              YuriQ
              wrote on last edited by
              #17

              Signal:
              @
              // Inside class definition:
              signals:
              void signalOfYourClass();
              @

              That's it. You don't need to make implementation of the function "signalOfYourClass".

              Public slot:
              @
              // Inside class definition:
              public slots:
              void slotOfYourClass();
              @

              Also you have to make implementation of function "slotOfYourClass".

              1 Reply Last reply
              0
              • H Offline
                H Offline
                herculis
                wrote on last edited by
                #18

                I wrote in contols class
                slot:
                void play()
                coz contols class has all the widgets.

                and in other class
                signals:
                void clicked();

                and wrote the function for play() and put it in controls class.
                Stills its not working ,showing the same error“no videoWindowControl or videoRendererControl, unable to add output node for video data”
                i this that play slot is unable to find the screen videosurface to show the video that why i am getting this error so how should i pass this screen class to play

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  YuriQ
                  wrote on last edited by
                  #19

                  Not exactly. I think you need signal in your controls-class and slot in your screen class.

                  1 Reply Last reply
                  0
                  • Y Offline
                    Y Offline
                    YuriQ
                    wrote on last edited by
                    #20

                    Also don't forget to emit signal and to make connection between signal and slot.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      herculis
                      wrote on last edited by
                      #21

                      thing is my slot is play and function play() is now written in screen class
                      now if i emit signal which is named as'clicked' in play function its gives error coz it donot identifies clicked as its not defined in screen class

                      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