Results 1 to 6 of 6

Thread: Access a class without using Signals/Slots

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Access a class without using Signals/Slots

    Hi.
    I have
    Qt Code:
    1. connect ( newProject, SIGNAL ( returnUserInput ( QString, QString ) ),
    2. existProject, SLOT ( slotReturnUserInput ( QString, QString ) ) );
    To copy to clipboard, switch view to plain text mode 
    What would the code be if I didn't use the Signal/Slot procedure to accomplish the same thing?

    Thanks

    Note: my email has changed to "edperry26@gmail.com"

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access a class without using Signals/Slots

    newProject would have to contain a class pointer to existProject and call the function directly, just as a standard C++ method call. Yeuck.

  3. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Access a class without using Signals/Slots

    Thanks Yeuck, but that is what I'm looking for. In my 84 years there are a lot things I've forgoteen. I started programming in 1970. long btfore C, C++, windows Etc. Since 2000, I've been using Linux, and Qt since I heard of it. (I can't remember when). I am having trouble and/or patience in relearning a language I haven't used in ten years or so and thought this might be a simple way getting a translation from Singnal/Slots to C++.

    Thanks again for you reply

    pete Perry

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access a class without using Signals/Slots

    Pete - also being an old timer and not used to OOP, when all else fails, I just use a global variable. Not elegant, but it works.

  5. #5
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Access a class without using Signals/Slots

    What I need is the actual C++ code to do what I showed in my Signal/Slots. I did a lot o programming in C++ when I was programming in "XP" and before MS, but I think seeing the actual C++ version of my Qt sample will be most helpful in triggering my old weary mind.

    Thanks

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access a class without using Signals/Slots

    Well, the connect call doesn't translate to much, but if we add a signal emit also, you'll get something like this:

    Qt Code:
    1. CLASS B;
    2. CLASS A
    3. {
    4. public:
    5. B *bptr;
    6. void somefunc();
    7. };
    8.  
    9. CLASS B
    10. {
    11. public:
    12. slotReturnUserInput(QString qs1, QString qs2);
    13. };
    14.  
    15. void A::somefunc()
    16. {
    17. bptr->slotReturnUserInput("sometext","sometext");
    18. }
    19.  
    20. void B::slotReturnUserInput(QString qs1, QString qs2)
    21. {
    22. some code
    23. }
    To copy to clipboard, switch view to plain text mode 

    Personally however, if your going along that route, I'd use "getUserInput" in class A and get class B to call it, rather than having class A call back class B, which is just nasty and not self-contained.

  7. The following user says thank you to squidge for this useful post:

    impeteperry (10th January 2010)

Similar Threads

  1. How to access the UI from another class ?
    By fitzy in forum Qt Programming
    Replies: 22
    Last Post: 20th July 2016, 15:21
  2. regarding signals/slots
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2007, 10:32
  3. Signals and slots
    By sylvarant in forum Newbie
    Replies: 4
    Last Post: 11th September 2007, 16:48
  4. Replies: 5
    Last Post: 14th July 2006, 23:42
  5. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 13:49

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.