Results 1 to 16 of 16

Thread: How to link one class to another??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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
    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

  5. #5
    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,
    _

  6. #6
    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.

  7. #7
    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.


  8. #8
    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

  9. #9
    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,
    _

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

  11. #11
    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,
    _

  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??


Similar Threads

  1. Replies: 5
    Last Post: 13th January 2014, 09:24
  2. Replies: 11
    Last Post: 5th May 2011, 14: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, 07:25
  4. Replies: 3
    Last Post: 27th December 2008, 19:34
  5. OSX Mac NSApplication class link?
    By patrik08 in forum General Programming
    Replies: 1
    Last Post: 24th June 2006, 23: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.