Nominate our 2022 Qt Champions!

How to link one class to another??

  • Hello guys I am bulding a videoplayer in VC++ and i have build one but i have one problem i have the screen of the player in one layout(class) and the control in other layout(class ).So now i have to link this classes so that when i will hit the play button from control the video shuld play in other layout.
    Could anyone please help me in this.

  • Use signals and slots mechanism. Make custom signals in control-class and corresponding slots in the player-class.

  • can u give me any example or just a rough abtract how to write it

  • You can find some useful info "here":

  • Ya i knw i have to use signals and slots and i have used it also but as the video screen code is in diffrent class and signals slots is in different class they cant communicate with each other.
    How to do that

  • I don't get it. Why can't they communicate with each other? Is it compilation error or runtime error? More detailed description would be great.

  • "no videoWindowControl or videoRendererControl, unable to add output node for video data"
    I am getting this error as the screen is in other class and the paly button is in other class they cant communicate coz paly button dont know that there is a screen(video output) in the class as they are not linked together.

  • Can you show your code?

  • code i too big and I ahve just added on class in that and i want to link that class to other class so that play can acess the video screen and the video gets displayed

  • Can you make simple sample code to illustrate the issue? Some code that I could run to see what exactly is the issue.

  • class screen
    code for video output whcih has only screen to show the video

    class controls
    It has widgets like play button ,slider etc
    and signal slot for play button
    connect(playbutton, SIGNAL(clicked()), this, SLOT(play()));
    and function for play .
    contols:: play()
    code to play the video
    and when we run the code then there are two windows(layouts) one has screen and one has all control widgets.Now I want when i click on play button the video shuld play in the other window.but the thing is that play function button dont know that there is a screen class in the code so i want to link it with the class.Previous the screen function was in the same class and it was working fine now its in different class so cant play the video.

  • You can use signals and slots like this:

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

    QTextEdit editor1;
    QTextEdit editor2;;;

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

    return app.exec();

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

  • 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

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

  • 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

  • Signal:
    // Inside class definition:
    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".

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

    and in other class
    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

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

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

  • 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

Log in to reply