Results 1 to 4 of 4

Thread: <Solved> Pointer to Calling class is needed

  1. #1
    Join Date
    Aug 2015
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default <Solved> Pointer to Calling class is needed

    Hi there,

    I've a problem with the old topic "Signal from one class to another class".

    To clearify my situation:

    I have A which calls B (a modal QDialog, so it is without parent). B has a button, when pressed a function in A is calling, this way works. But the other way round I have the problem...

    I initialize B like this:

    b = new B();
    and later in the "openFunction":
    b->setFixedSize(b->minimumSize());
    testbshow();

    and now, in B I want this:
    connect(A, SIGNAL(CallB()), this, SLOT(FunctionB()));

    Because B should be Modal I can't do anything like this (maybe, I'm only don't know how I get B modal with this line):
    b = new B(this);

    I hope someone has a idea what I can do, so that B can get a signal from A.

    -casisto
    Last edited by Casisto; 22nd August 2015 at 19:58.

  2. #2
    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: Pointer to Calling class is needed

    Quote Originally Posted by Casisto View Post
    I have A which calls B (a modal QDialog, so it is without parent).
    What does modality have to do with parent/child relationship?

    Quote Originally Posted by Casisto View Post
    and now, in B I want this:
    connect(A, SIGNAL(CallB()), this, SLOT(FunctionB()));
    Isn't it way easier to do the connect inside A, where you have both a pointer to A and B?
    E.g. right after creating B

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Casisto (22nd August 2015)

  4. #3
    Join Date
    Aug 2015
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Pointer to Calling class is needed

    Thanks so much!

    I didn't know that I can do this so. I ever thought the connect has to been in the class where the function is declared.

  5. #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: Pointer to Calling class is needed

    Quote Originally Posted by Casisto View Post
    I didn't know that I can do this so. I ever thought the connect has to been in the class where the function is declared.
    No, that's the beauty of signal/slots.
    Neither the sender nor the receiver need to know about the other or the connect, the connection can be done by any code that knows both objects.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 23rd May 2015, 14:57
  2. Replies: 7
    Last Post: 2nd September 2010, 20:42
  3. class calling other class functions?
    By Hardstyle in forum Newbie
    Replies: 4
    Last Post: 2nd June 2010, 03:38
  4. QPushButton not calling repaint when needed?
    By Enygma in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2010, 18:03
  5. Accessing a class Object by pointer in another class
    By pdoria in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 16:59

Tags for this Thread

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.