Results 1 to 16 of 16

Thread: How to link one class to another??

  1. #1
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.
    thanks.

  2. #2
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.
    thanks.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to link one class to another??

    Use signals and slots.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link one class to another??


  5. #5
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to link one class to another??

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link one class to another??

    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,
    _

  7. #7
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to link one class to another??

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to link one class to another??

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to link one class to another??

    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

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link one class to another??

    Qt Code:
    1. connect(c, SIGNAL(play()), s, SLOT(play()));
    2. // c Is an instance of controls
    3. // s is an instance of screen
    4. // controls needs a signal play()
    5. // screen needs a slot play()
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  11. #11
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to link one class to another??

    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().

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link one class to another??

    In main.cpp you need to use the fully qualified name for connect, i.e. it is a static method in QObject
    Qt Code:
    1. QObject::connect(&c, SIGNAL(...), &s, SLOT(...));
    To copy to clipboard, switch view to plain text mode 

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

    Cheers,
    _

  13. #13
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to link one class to another??

    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.

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link one class to another??

    Quote Originally Posted by herculis View Post
    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().

    Quote Originally Posted by herculis View Post
    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,
    _

  15. #15
    Join Date
    Jul 2014
    Posts
    39
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to link one class to another??

    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.

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link one class to another??

    Quote Originally Posted by anda_skoa View Post
    Post the screen and control class.
    Let me rephrase that

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

    Cheers,
    _

Similar Threads

  1. Replies: 5
    Last Post: 13th January 2014, 10:24
  2. Replies: 11
    Last Post: 5th May 2011, 15:05
  3. How to link a Push Button with a Web link ???
    By prajnaranjan.das in forum Newbie
    Replies: 3
    Last Post: 10th December 2010, 08:25
  4. Replies: 3
    Last Post: 27th December 2008, 20:34
  5. OSX Mac NSApplication class link?
    By patrik08 in forum General Programming
    Replies: 1
    Last Post: 25th June 2006, 00:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.