Results 1 to 1 of 1

Thread: connect() returning FALSE

  1. #1
    Join Date
    Jul 2020
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default connect() returning FALSE

    I'm in Linux 32bit, using Qt4.8.6 and gcc 4.9.1.

    I wrote a program having a main window with some buttons which in turn trigger some other small dialogs.
    One of these dialogs (CpmUserDialog) has 2 buttons (OK and Cancel) and a spinner for numeric input.
    I connected the Cancel button to the standard QDialog::reject() slot.
    I connected the OK button to a custom slot I wrote (okUser()).

    The problem is the OK button does nothing when clicked, and by digging I found out it's because connect() returns FALSE on this button. "Digging" means a snippet like this: (in ui_CpmUserDialog.h)
    Qt Code:
    1. const bool connected1 = QObject::connect(pushButton1, SIGNAL(clicked()), CpmUserDialog, SLOT(okUser()));
    2. const bool connected2 = QObject::connect(pushButton2, SIGNAL(clicked()), CpmUserDialog, SLOT(reject()));
    3. printf("OK connected?: %s\n", (connected1==0?"NO":"YES"));
    4. printf("Cancel connected?: %s\n", (connected2==0?"NO":"YES"));
    To copy to clipboard, switch view to plain text mode 
    The Cancel button works just fine, connect() returns TRUE for this button.

    When this dialog is shown, in the console I get this:
    Qt Code:
    1. OK connected?: NO
    2. Cancel connected?: YES
    To copy to clipboard, switch view to plain text mode 
    There are NO compilation errors and NO runtime errors in the console output.

    And I don't know how to figure out the exact cause of the connect() failure.

    This dialog has three pieces of code: CpmUserDialog.h, CpmUserDialog.cpp and CpmUserDialog.ui

    My approach for custom slots was to define them in a subclass and manually insert their names in the .ui file in place of a dummy slot (like for instance accept()) generated using Qt Designer.

    Here are the snippets:

    CpmUserDialog.h (full code):
    =====================
    Qt Code:
    1. #ifndef CPMUSERDIALOG_H
    2. #define CPMUSERDIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. #include "ui_CpmUserDialog.h"
    7.  
    8. namespace CPM {
    9. extern unsigned char user_new;
    10. }
    11.  
    12. class CpmUserDialog : public QDialog, public Ui::CpmUserDialog {
    13. Q_OBJECT
    14. private slots:
    15. void okUser();
    16. public:
    17. CpmUserDialog(QWidget *parent = 0);
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 
    CpmUserDialog.cpp (full code):
    =======================
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "CpmUserDialog.h"
    4.  
    5. CpmUserDialog::CpmUserDialog(QWidget *parent) : QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint) {
    6. setupUi(this);
    7. }
    8.  
    9. void CpmUserDialog::okUser() {
    10. CPM::user_new = spinBox1->value();
    11. accept();
    12. }
    To copy to clipboard, switch view to plain text mode 

    CpmUserDialog.ui (only the <connections> section):
    ======================================
    Qt Code:
    1. <connections>
    2. <connection>
    3. <sender>pushButton1</sender>
    4. <signal>clicked()</signal>
    5. <receiver>CpmUserDialog</receiver>
    6. <slot>okUser()</slot>
    7. <hints>
    8. <hint type="sourcelabel">
    9. <x>20</x>
    10. <y>20</y>
    11. </hint>
    12. <hint type="destinationlabel">
    13. <x>20</x>
    14. <y>20</y>
    15. </hint>
    16. </hints>
    17. </connection>
    18. <connection>
    19. <sender>pushButton2</sender>
    20. <signal>clicked()</signal>
    21. <receiver>CpmUserDialog</receiver>
    22. <slot>reject()</slot>
    23. <hints>
    24. <hint type="sourcelabel">
    25. <x>20</x>
    26. <y>20</y>
    27. </hint>
    28. <hint type="destinationlabel">
    29. <x>20</x>
    30. <y>20</y>
    31. </hint>
    32. </hints>
    33. </connection>
    34. </connections>
    To copy to clipboard, switch view to plain text mode 

    The weird thing is that other dialogs don't have this problem. For instance, check out the ZIP attachment with the sources for another dialog (RenameDialog). This one works just fine. In it I used the same approach for implementing the custom slots.
    Attached Files Attached Files

Similar Threads

  1. QPainting::begin() is returning false on Linux
    By martinl.bertrand in forum Qt Programming
    Replies: 0
    Last Post: 1st April 2016, 17:48
  2. QObject->inherits() troubles: Keeps returning false
    By JPNaude in forum Qt Programming
    Replies: 6
    Last Post: 3rd March 2010, 09:42
  3. qdbus connect return always FALSE
    By ciberkids in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2009, 15:17
  4. connect returning false
    By thru in forum Newbie
    Replies: 3
    Last Post: 28th April 2009, 20:58
  5. connect returns false
    By krivenok in forum Qt Programming
    Replies: 6
    Last Post: 21st February 2006, 21:01

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.