Results 1 to 2 of 2

Thread: Overwrite Qt slot ...

  1. #1
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Overwrite Qt slot ...

    Hi, all:

    Is it possible to overwrite Qt slot?

    For instance:

    CFather:
    Qt Code:
    1. class CFather : public QMainWindow
    2. {
    3. Q_OBJECT
    4. .....
    5. protected slots:
    6. void about();
    7. }
    8.  
    9. void CFather::about()
    10. {
    11. QMessageBox::information(this,
    12. "Father",
    13. "......");
    14. }
    To copy to clipboard, switch view to plain text mode 


    CSon:
    Qt Code:
    1. class CSon : public CFather
    2. {
    3. Q_OBJECT
    4. .....
    5. protected slots:
    6. void about();
    7. }
    8.  
    9. void CSon::about()
    10. {
    11. QMessageBox::information(this,
    12. "Son",
    13. "......");
    14. }
    To copy to clipboard, switch view to plain text mode 


    I just want to realize:

    A CFather object will call CFather::about() when the menu item "about" is invoked.
    A CSon object will call CSon::about() when the menu item "about" is invoked.
    (Note: CFather and CSon are almost the same QMainWindow with only a little bit modification.
    But, I just want the about() will invoke two different dialogs, with clear indication that this is a "Son" or a "Father" window)

    I tried "virtual" already, but whenever I clicked "OK" on the poped CSon:about() QMessageBox, it will CSon QMessageBox once again. That is to say, I've got to click "OK" twice to close QMessageBox thoroughly.

    How to deal with this problem?

    Best Regards
    JIA
    Welcome to Vision Open
    http://www.visionopen.com

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Overwrite Qt slot ...

    Slots are fundamentally the same as functions. If the slot is declared virtual, you can override it. If it isn't, you can't.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Overwrite mode in QLineEdit
    By tarod in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2011, 15:43
  2. Overwrite QKeyEvent
    By haldrik in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2008, 19:43
  3. getSaveFileName overwrite check question
    By Lexrst in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 09:26
  4. Subclassing QSqlTableModel to overwrite setQuery
    By montuno in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2007, 10:32
  5. Inherit and Overwrite signals
    By shaselsc in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2006, 15:39

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.