Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: my slots don't appear in the signal slot editor

  1. #1
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default my slots don't appear in the signal slot editor

    I don't mind coding my own connect statements but I am trying to learn Qt designer

    This code works!
    Qt Code:
    1. // part of the .h file
    2. private:
    3. Ui::ECalc1Class ui;
    4.  
    5. private slots: // my methods...yes I tried public:
    6. void addClicked();
    7. void subClicked();
    8. void mulClicked();
    9. void divClicked();
    10.  
    11. ____________________________________________
    12.  
    13. #include "ecalc1.h"
    14. #include <QMessageBox>
    15. ECalc1::ECalc1(QWidget *parent)
    16. : QWidget(parent)
    17. {
    18. ui.setupUi(this);
    19. connect( ui.pushButtonAdd, SIGNAL(clicked()), this, SLOT(addClicked()) );
    20. connect( ui.pushButtonSub, SIGNAL(clicked()), this, SLOT(subClicked()) );
    21. connect( ui.pushButtonMul, SIGNAL(clicked()), this, SLOT(mulClicked()) );
    22. connect( ui.pushButtonDiv, SIGNAL(clicked()), this, SLOT(divClicked()) );
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    QtDesigner doesn't pull the slots from your source code, but from the ui file. So if you want to access them via designer, you'll need to right click an object and use the "change signals/slots" menu item. Add them there and they will appear.

    BTW, the generated code by designer calls connectSlotsByName() which means that if you have a function like "void on_button1_clicked();" you don't need to connect() it, as it'll be done for you when you call setupui(). Saves doing it yourself.

  3. The following user says thank you to squidge for this useful post:

    waynew (9th January 2010)

  4. #3
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default

    you'll need to right click an object and use the "change signals/slots" menu item.

    where do I find these objects?

    I have a column "project explorer" and other columns but I do not see any window containing "objects"

    OOPS! BTW I am using the Eclipse QT designer plugin!

    The program works but....

    Found the "object"

    I added addClicked() to the list of slots but the slots in the editor is grayed out

    the slots are grayed out in the editor (drag a red line)

    so I went to the "other "editor below and entered 3 more connects.

    The program now works (as it did when I wrote the connect statements myself.)

    Qt Code:
    1. #include "trycalc.h"
    2. #include <QMessageBox>
    3. trycalc::trycalc(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. ui.setupUi(this);
    7. connect(ui.pushButtonAdd,SIGNAL(clicked()),this,SLOT(addClicked()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    Final questions are:
    (1) why are all slots grayed out in the "drag red line editor from "above" button" list?
    These "gray" slots are NOT grayed out in the "connect" editor below
    (2) where are the other 3 connect statements???


    answer to (2) : buried in the hieroglyphics of a .moc file. I guess this is to be expected since the .cpp file is not at all generated by a tool! My single connect statement remains.

    and my connect statement did not show up in the signal/slot editor below!
    Last edited by wysota; 3rd December 2009 at 10:42.

  5. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    slots will be grayed out if the slot is incompatible with the signal. For example, a slot expecting an int will not accept a signal that emits a char *

    All connect statements generated by designer will be present in the header file and executed when setupui is called.

  6. #5
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: my slots don't appear in the signal slot editor

    OK but why do these slots show up as choices in the Qt C++ signal slot tab below???

    and with "my" connect statement tha works, how do I fix the other 3

    for subtract, mutiply and divide

    connect(ui.pushButtonAdd,SIGNAL(clicked()),this,SL OT(addClicked()));

    QAbstratButton has
    Signals

    *
    void clicked ( bool checked = false ) argument optional
    *
    void pressed ()
    *
    void released ()
    *
    void toggled ( bool checked )

    *
    1 signal inherited from QWidget
    *
    1 signal inherited from QObject

    My slots are all void void
    Last edited by landonmkelsey; 2nd December 2009 at 17:30.

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    Your slots shouldn't be all void void. If there are no parameters, the parameter list should be empty, otherwise the slots will be grayed out in designer.

    If you create a slot in designer and name it "foo()", then it will allow you to assign the clicked() event to that slot using the "Edit signals/slots" editor (ie, you drag a line from the button to whatever)

    If you are still having problems, post your project.

  8. #7
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: my slots don't appear in the signal slot editor

    I have tar'ed and gzip'ed the workspace (Eclipse) for the project attached

    If you don't have Eclipse with Qt designer plugin, I can export the files and "retar"

  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    You seem to have forgotten to attach the project.

    Secondly, have you tried to open the .ui file in QtDesigner itself rather than the Eclipse plugin to make sure it isn't a bug in the plugin?

  10. #9
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default

    I exported necessary files via tar and gzip.

    I removed *.o and executable

    -rw-rw-r--. 1 qt4 qt4 1225203 2009-12-02 19:04 trycalc.tar.gz
    too big to attach.

    Do you have an email I could send it to?

    I will try using the designer alone to look at what is going on!

    where does one say thanks!

    this time I clicked on "edit" and was allowed to enter the 4 methods/slots.

    However when I dragged the red line out of a pushbutton, the choices were grayed out.

    This looks like a bug or missing feature.

    Who wants to limit slots to base class slots?

    Again, the C++ signal slot editor tab near the bottom shows and allows selection of user slots.

    Hitting F4 or the editor that pops up from the icon at the top doesn't allow
    Last edited by wysota; 3rd December 2009 at 10:42.

  11. #10
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: my slots don't appear in the signal slot editor

    may be this:
    Qt Code:
    1. clicked(bool c = false)
    To copy to clipboard, switch view to plain text mode 
    ? void is actually not equal to default argument.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: my slots don't appear in the signal slot editor

    Please edit your posts if you have anything to add instead of replying to yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #12
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: my slots don't appear in the signal slot editor

    wysota:
    just curious...are you a Nokia (formerly Trolltech) employee??

    Tanuli-no:
    thanks! clicked(bool c = false) occurred to me even though it is really unnecessary.

    Come to think of it,
    he whole original parameter spec should really be used anyway!

    Assuming that is correct (I think it is) why are the user slots appearing at the bottom dialog (tab) and not at the top dialog (F4/icon)?
    The following compiled and ran but with warning:
    Object::connect: No such signal QPushButton::clicked(bool c) in trycalc.cpp:7
    Object::connect: (sender name: 'pushButtonAdd')
    Object::connect: (receiver name: 'trycalcClass')


    Qt Code:
    1. #ifndef TRYCALC_H
    2. #define TRYCALC_H
    3.  
    4. #include <QtGui/QWidget>
    5. #include "ui_trycalc.h"
    6.  
    7. class trycalc : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. trycalc(QWidget *parent = 0);
    13. ~trycalc();
    14.  
    15. private:
    16. Ui::trycalcClass ui;
    17. public slots:
    18. void addClicked(bool c = false);
    19. void subClicked(bool c = false);
    20. void mulClicked(bool c = false);
    21. void divClicked(bool c = false);
    22.  
    23. };
    24.  
    25. #endif // TRYCALC_H
    26.  
    27.  
    28. #include "trycalc.h"
    29. #include <QMessageBox>
    30. trycalc::trycalc(QWidget *parent)
    31. : QWidget(parent)
    32. {
    33. ui.setupUi(this);
    34. connect(ui.pushButtonAdd,SIGNAL(clicked(bool c)),this,SLOT(addClicked(bool c;
    35. }
    36.  
    37. trycalc::~trycalc()
    38. {
    39.  
    40. }
    41. //
    42. void trycalc::addClicked(bool c)
    43. {
    44.  
    45. QString qstring1 = ui.lineEdit->text();
    46. QString qstring2 = ui.lineEdit_2->text();
    47.  
    48. bool ok1 = true;
    49. bool ok2 = true;
    50. float f1 = qstring1.toFloat(&ok1);
    51. float f2 = qstring2.toFloat(&ok2);
    52. if( qstring1.length() == 0
    53. || qstring2.length() == 0
    54. || !ok1
    55. || !ok2)
    56. {
    57. QMessageBox mb("Adder",
    58. "missing or bad entry",
    59. QMessageBox::Warning,
    60. QMessageBox::NoButton ,
    61. QMessageBox::NoButton);
    62. mb.exec();
    63. ui.lineEdit->clear();
    64. ui.lineEdit_2->clear();
    65. ui.lineEdit_3->clear();
    66. return;
    67. }
    68. float f3 = f1 + f2;
    69. QString qstring3;
    70. qstring3.setNum(f3);
    71. ui.lineEdit_3->setText(qstring3);
    72. }
    73. void trycalc::subClicked(bool c)
    74. {
    75. QString qstring1 = ui.lineEdit->text();
    76. QString qstring2 = ui.lineEdit_2->text();
    77.  
    78. bool ok1 = true;
    79. bool ok2 = true;
    80. float f1 = qstring1.toFloat(&ok1);
    81. float f2 = qstring2.toFloat(&ok2);
    82. if( qstring1.length() == 0
    83. || qstring2.length() == 0
    84. || !ok1
    85. || !ok2)
    86. {
    87. QMessageBox mb("Adder",
    88. "missing or bad entry",
    89. QMessageBox::Warning,
    90. QMessageBox::NoButton ,
    91. QMessageBox::NoButton);
    92. mb.exec();
    93. ui.lineEdit->clear();
    94. ui.lineEdit_2->clear();
    95. ui.lineEdit_3->clear();
    96. return;
    97. }
    98. float f3 = f1 - f2;
    99. QString qstring3;
    100. qstring3.setNum(f3);
    101. ui.lineEdit_3->setText(qstring3);
    102. }
    103. void trycalc::mulClicked(bool c)
    104. {
    105.  
    106. QString qstring1 = ui.lineEdit->text();
    107. QString qstring2 = ui.lineEdit_2->text();
    108.  
    109. bool ok1 = true;
    110. bool ok2 = true;
    111. float f1 = qstring1.toFloat(&ok1);
    112. float f2 = qstring2.toFloat(&ok2);
    113. if( qstring1.length() == 0
    114. || qstring2.length() == 0
    115. || !ok1
    116. || !ok2)
    117. {
    118. QMessageBox mb("Adder",
    119. "missing or bad entry",
    120. QMessageBox::Warning,
    121. QMessageBox::NoButton ,
    122. QMessageBox::NoButton);
    123. mb.exec();
    124. ui.lineEdit->clear();
    125. ui.lineEdit_2->clear();
    126. ui.lineEdit_3->clear();
    127. return;
    128. }
    129. float f3 = f1 * f2;
    130. QString qstring3;
    131. qstring3.setNum(f3);
    132. ui.lineEdit_3->setText(qstring3);
    133. }
    134. void trycalc::divClicked(bool c)
    135. {
    136.  
    137. QString qstring1 = ui.lineEdit->text();
    138. QString qstring2 = ui.lineEdit_2->text();
    139.  
    140. bool ok1 = true;
    141. bool ok2 = true;
    142. float f1 = qstring1.toFloat(&ok1);
    143. float f2 = qstring2.toFloat(&ok2);
    144. if( qstring1.length() == 0
    145. || qstring2.length() == 0
    146. || !ok1
    147. || !ok2
    148. || f2==0.)
    149. {
    150. QMessageBox mb("Adder",
    151. "missing or bad entry",
    152. QMessageBox::Warning,
    153. QMessageBox::NoButton ,
    154. QMessageBox::NoButton);
    155. mb.exec();
    156. ui.lineEdit->clear();
    157. ui.lineEdit_2->clear();
    158. ui.lineEdit_3->clear();
    159. return;
    160. }
    161. float f3;
    162. if (f2 != 0.) f3 = f1 / f2;
    163. QString qstring3;
    164. qstring3.setNum(f3);
    165. ui.lineEdit_3->setText(qstring3);
    166. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by landonmkelsey; 3rd December 2009 at 16:04. Reason: add on not posting a new post as directed

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: my slots don't appear in the signal slot editor

    Quote Originally Posted by landonmkelsey View Post
    wysota:
    just curious...are you a Nokia (formerly Trolltech) employee??
    No, I'm not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #14
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    What is this?

    Qt Code:
    1. void addClicked(bool c = false);
    2. void subClicked(bool c = false);
    3. void mulClicked(bool c = false);
    4. void divClicked(bool c = false);
    To copy to clipboard, switch view to plain text mode 

    If you don't care about the state, it should be:

    Qt Code:
    1. void addClicked();
    2. void subClicked();
    3. void mulClicked();
    4. void divClicked();
    To copy to clipboard, switch view to plain text mode 

    As mentioned previously.

  16. #15
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: my slots don't appear in the signal slot editor

    somebody recommended a fix and I was giving it a shot

    Your recommendation describes my original code.

    My original code compiled and ran without warning/error.

  17. #16
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    Attach your .ui file

  18. #17
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: my slots don't appear in the signal slot editor

    attached but....one could( in 30 seconds), simply drag 3 lineedtit controls and a pushbutton onto the designer surface and try what is supposed to be the purpose of the designer

    code produced from a graphical start...the slots are coded, connects are coded, etc

    the original question. was:
    Attached Files Attached Files

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: my slots don't appear in the signal slot editor

    So what's the problem exactly? The slots you added are available in Designer's signal/slot editor. Isn't it what you wanted?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #19
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: my slots don't appear in the signal slot editor

    from first post

    (1) why are all slots grayed out in the "drag red line" editor from F4 or

    the edit signals/slots icon above but

    These "grayed" slots are NOT grayed out in the "C++ Signals/Slotst" editor tab below

  21. #20
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: my slots don't appear in the signal slot editor

    Quote Originally Posted by landonmkelsey View Post
    attached but....one could( in 30 seconds), simply drag 3 lineedtit controls and a pushbutton onto the designer surface and try what is supposed to be the purpose of the designer
    Yes, and we said that worked fine for us, hence the reason for wanting YOUR ui file which you said doesn't work.

    I've just opened your ui file, deleted the connections, and then use the red line signal slot editor to connect the buttons to your appropriate functions (addClicked, etc) with no problems at all. I didn't have to use the bottom box at all.

    So, whats the problem? You ARE selecting a signal before attempting to select a slot? Otherwise the slots WILL be grayed out as they are not usable at that stage.

Similar Threads

  1. Queuing problem with signal and slots
    By montylee in forum Qt Programming
    Replies: 4
    Last Post: 20th November 2009, 06:11
  2. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  3. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  4. Signal & Slot editor
    By Ishark in forum Qt Tools
    Replies: 4
    Last Post: 28th May 2008, 15:20
  5. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 10:10

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.