Results 1 to 6 of 6

Thread: [Signals & Slots] Custom class' signal not detected

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default [Signals & Slots] Custom class' signal not detected

    Hello All,

    I've looked into how to write a class with QObject's inheritance so I can use signals as I need feedback from said class. The trouble is, I'm not sure if I defined the signal correctly, as it differs from the Signals & Slots example.

    My code is as follows:

    Qt Code:
    1. class worker : public QObject{
    2. Q_OBJECT
    3. public:
    4. worker();
    5.  
    6. void execute (bool isExecuting){
    7. if (isExecuting==true){
    8. //do stuff
    9. emit scanUpdate(); //differs from the example's ValueChanged(int newValue)
    10. }
    11. else return;
    12. }
    13.  
    14. signals:
    15. void scanUpdate();
    16. }
    17.  
    18. class mainClass : public QMainWindow, Ui::MainWindow
    19. {
    20. Q_OBJECT
    21.  
    22. public:
    23. mainClass() : QMainWindow()
    24. {
    25. setupUi(this);
    26. lib=new worker;
    27. connect(lib,SIGNAL(scanUpdate()),this,SLOT(pbScanUpdate()));
    28.  
    29. while(1){ lib->execute(true); }
    30.  
    31. }
    32. worker *lib;
    33. public slots:
    34. void pbScanUpdate(){
    35. //do stuff which can only occur after lib->execute has been called
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

    This compiles ok with the Q_OBJECT declarations, but I never see pbScanUpdate() running. What could I be missing?


    Thanks in advance,
    Mr_Cloud
    Last edited by Mr_Cloud; 26th July 2012 at 06:58.

  2. The following user says thank you to Mr_Cloud for this useful post:

    zhy282289 (26th July 2012)

Similar Threads

  1. Signals Slots and Class Pointers
    By Atomic_Sheep in forum Newbie
    Replies: 18
    Last Post: 7th September 2012, 09:08
  2. Custom QTreeWidgetItem class and signals&slots issue
    By devla in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2012, 00:15
  3. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 11:14
  4. Replies: 12
    Last Post: 23rd June 2008, 08:05
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.