Results 1 to 5 of 5

Thread: Signal inside an abstract class

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal inside an abstract class

    Hi there guys. I have this abstract class below.
    Qt Code:
    1. class Page : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit Page(QObject *parent = 0);
    6. virtual void start_downloading() = 0;
    7. signals:
    8. void done();
    9. public slots:
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 
    As you can see that there is a signal Page::done() in the class. I have a bunch of concrete classes that inherit this class and the concrete classes will emit the signal Page::done() above. I have a separate class that works with the concrete classes and problem is connecting the above signal to any slot and I suppose its because the signal exists in an abstract class. Is there a way of connecting this signal.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Signal inside an abstract class

    The concrete classes inheriting abstract Page class will also inherit the signals (and slots), so connecting to signal should be just as usual, should not be any different for Abstract class signal (or slot) / Concrete class signal (or slot).
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Signal inside an abstract class

    The "signals" keyword is basically defining a "protected" section in the class definition, so your derived classes will inherit the methods you have defined as signals with protected access.

    You may have to qualify the names with Page:: when you connect (and use the "PointerToMemberFunction" version of QObject::connect()).
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  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: Signal inside an abstract class

    Quote Originally Posted by d_stranz View Post
    The "signals" keyword is basically defining a "protected" section in the class definition
    Actually Qt5 had to switch this to "public" in order to make the function pointer based connect work.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Signal inside an abstract class

    Actually Qt5 had to switch this to "public" in order to make the function pointer based connect work.
    Hmm, I must have been looking at older documentation. Making it public makes sense, though. Thanks for the correction.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. cannot instantiate abstract class
    By Higgs in forum Newbie
    Replies: 2
    Last Post: 6th January 2014, 21:41
  2. abstract custome QWidget class
    By migel in forum Newbie
    Replies: 1
    Last Post: 12th July 2011, 10:41
  3. Abstract base class and inherited class members
    By JovianGhost in forum General Programming
    Replies: 3
    Last Post: 19th March 2010, 13:32
  4. MVC - Abstract Widget Base Class - setupUI
    By SenSej in forum Newbie
    Replies: 0
    Last Post: 13th October 2008, 11:44
  5. Replies: 2
    Last Post: 25th August 2006, 12:35

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.