PDA

View Full Version : How to link one class to another??



herculis
14th August 2014, 10:34
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.
thanks.

herculis
14th August 2014, 10:36
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.
thanks.

wysota
14th August 2014, 11:34
Use signals and slots.

anda_skoa
14th August 2014, 12:07
http://qt-project.org/doc/qt-5/signalsandslots.html

Cheers,
_

herculis
14th August 2014, 12:16
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

anda_skoa
14th August 2014, 12:19
Signal/Slot connections do not require both objects to be of the same class.
The only requirement is that both are derived from QObject.

Cheers,
_

herculis
14th August 2014, 12:27
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), this, SLOT));
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.

wysota
14th August 2014, 13:10
Expose signals from one class, slots the other class (and vice versa if needed) and in some piece of code which has knowledge of both the instances (e.g. a window containing/controlling them both), make signal-slot connections between them.

herculis
14th August 2014, 14:21
Ya i read the article but How to define signals and slots can you plz give me one short example so that i will know how they are comunicating in different class

anda_skoa
14th August 2014, 15:30
connect(c, SIGNAL(play()), s, SLOT(play()));
// c Is an instance of controls
// s is an instance of screen
// controls needs a signal play()
// screen needs a slot play()


Cheers,
_

herculis
14th August 2014, 17:19
I build the instance like
screen c;
control s;
and put it in connect but its not identifying the intance showing error in that and i wrote this connect inctruction in main().

anda_skoa
14th August 2014, 17:33
In main.cpp you need to use the fully qualified name for connect, i.e. it is a static method in QObject


QObject::connect(&c, SIGNAL(...), &s, SLOT(...));


Btw, if you get an error there is not point in just saying you got one without posting it.

Cheers,
_

herculis
15th August 2014, 09:45
I did what you told but still i m getting error "no videoWindowControl or videoRendererControl, unable to add output node for video data" actually whats happening is that play button is not able to access tha screen as the screen is in different class and i m using qmediaplayer for tha screen so it is also a class and i have to connect the play function to qmediaplayer.So I dont have any idea how to connect all this please help.

anda_skoa
15th August 2014, 10:31
I did what you told but still i m getting error "no videoWindowControl or videoRendererControl, unable to add output node for video data"

That has nothing to do with the connect.
It is from QMediaPlayer and complains that you don't have any output surface set. see QMediaPlayer::setVideoOutput().



actually whats happening is that play button is not able to access tha screen as the screen is in different class and i m using qmediaplayer for tha screen so it is also a class and i have to connect the play function to qmediaplayer.So I dont have any idea how to connect all this please help.

Post the screen and control class.

Cheers,
_

herculis
15th August 2014, 11:55
Ya
in screen class i have
class screen
{
QMediaPlayer::setVideoOutput()
and some declaration and commands
}
and in control class i have
connect(playbutton, SIGNAL(clicked()), this, SLOT(play()));
and function for play() which has qmediaplayer object.

anda_skoa
15th August 2014, 13:33
Post the screen and control class.


Let me rephrase that

Post at least the declarations of the screen and control class.

Cheers,
_