Results 1 to 6 of 6

Thread: Signal slot don't work

  1. #1
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Signal slot don't work

    I have no idea why signal slot don't work.There is no error at all:


    customers.h
    Qt Code:
    1. signals:
    2. void setFlagUp();
    To copy to clipboard, switch view to plain text mode 

    customers.cpp
    Qt Code:
    1. void Customers::on_pushButtonCustomersDialogAdd_clicked()
    2. {
    3. emit setFlagUp();
    4. this->close();
    5. }
    To copy to clipboard, switch view to plain text mode 


    mainwindow.h
    Qt Code:
    1. private slots:
    2. void setIsRecordSet();
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. Customers *cu = new Customers(this);
    2. connect(cu, SIGNAL(setFlagUp()),this, SLOT(setIsRecordSet()));
    3.  
    4. void MainWindow::setIsRecordSet(){
    5.  
    6. qDebug() << "WORKS";
    7. }
    To copy to clipboard, switch view to plain text mode 

  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: Signal slot don't work

    That looks good.

    I assume you have verified that both classes inherit QObject and have the Q_OBJECT macro in their class declaration.
    And I assume you have checked that the slot that emits the signal is called.

    But have you also checked the result of the connect()?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Signal slot don't work

    I have correct inheritance of QObject, Q_OBJECT macro as well.The slot is called, but i don't know how to check the connection?

  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 slot don't work

    The result or result type of a function in C++ is the string directly left of the function name in the documentation of a function.

    For QObject::connect() that would be QMetaObject::Connection, a value that can be treated like a bool.

    Cheers,
    _

  5. #5
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Signal slot don't work

    In the moment of initialisation it returns false.

  6. #6
    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 slot don't work

    Then you should have also gotten a warning on the application's output.
    That usually contains information what is going wrong.

    If you are using Qt5 you could also try the function pointer based connect and see if you get compile errors.

    Cheers,
    _

Similar Threads

  1. Signal/Slot connection doesn't work across DLLs
    By Liachtei in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2015, 17:08
  2. Replies: 1
    Last Post: 14th August 2014, 18:08
  3. Replies: 8
    Last Post: 7th November 2012, 15:10
  4. Qt Designer Drag widget for signal/slot configure on the Mac does not work
    By Caius13 in forum Qt Tools
    Replies: 0
    Last Post: 28th April 2010, 19:22
  5. can a single statement work in signal/slot mechanism
    By salmanmanekia in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2008, 09:24

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.