Results 1 to 6 of 6

Thread: SIGNAL and SLOT Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default SIGNAL and SLOT Problem

    Hi
    I 'm a beginner in QT.
    My class's slots in my code do not work!!


    test.cpp:

    Qt Code:
    1. #include <QHBoxLayout>
    2. #include <QVBoxLayout>
    3. #include "test.h"
    4.  
    5. FindDialog::FindDialog( QWidget *parent): QDialog(parent)
    6. {
    7. label = new QLabel(tr("Find &what:"));
    8. lineEdit = new QLineEdit;
    9. label->setBuddy(lineEdit);
    10.  
    11. caseCheckBox = new QCheckBox(tr("Mach &case"));
    12. backwardCheckBox = new QCheckBox(tr("Search &backward"));
    13.  
    14. findButton = new QPushButton(tr("&Find"));
    15. findButton->setDefault(true);
    16. findButton->setEnabled(false);
    17.  
    18. closeButton = new QPushButton(tr("Close"));
    19.  
    20. connect(lineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(this->enableFindButton(const QString &)));
    21. connect(findButton , SIGNAL(clicked()),this,SLOT(this->findClicked()));
    22. connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
    23.  
    24. QHBoxLayout *topLeftLayout = new QHBoxLayout;
    25. topLeftLayout->addWidget(label);
    26. topLeftLayout->addWidget(lineEdit);
    27.  
    28. QVBoxLayout *leftLayout = new QVBoxLayout;
    29. leftLayout->addLayout(topLeftLayout);
    30. leftLayout->addWidget(caseCheckBox);
    31. leftLayout->addWidget(backwardCheckBox);
    32.  
    33. QVBoxLayout *rightLayout = new QVBoxLayout;
    34. rightLayout->addWidget(findButton);
    35. rightLayout->addWidget(closeButton);
    36. rightLayout->addStretch();
    37.  
    38. QHBoxLayout *mainLayout = new QHBoxLayout;
    39. mainLayout->addLayout(leftLayout);
    40. mainLayout->addLayout(rightLayout);
    41. setLayout(mainLayout);
    42.  
    43. setWindowTitle(tr("Search"));
    44. setFixedHeight(sizeHint().height());
    45. }
    46.  
    47. void FindDialog::findClicked()
    48. {
    49. QString text = lineEdit->text();
    50. Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    51. if (backwardCheckBox->isChecked()) {
    52. emit findPrevious(text,cs);
    53. } else {
    54. emit findNext(text,cs);
    55. }
    56. }
    57.  
    58. void FindDialog::enableFindButton(const QString &text)
    59. {
    60. findButton->setEnabled(!text.isEmpty());
    61. }
    To copy to clipboard, switch view to plain text mode 


    test.h:

    Qt Code:
    1. #ifndef FINDDIALOG_H
    2. #define FINDDIALOG_H
    3.  
    4. #include <QtGui>
    5. #include <QDialog>
    6.  
    7. #include <QCheckBox>
    8. #include <QLabel>
    9. #include <QLineEdit>
    10. #include <QPushButton>
    11.  
    12. class FindDialog : public QDialog
    13. {
    14. Q_OBJECT
    15.  
    16. public :
    17. FindDialog(QWidget *parent = 0);
    18.  
    19. signals:
    20. void findNext(const QString &str , Qt::CaseSensitivity cs);
    21. void findPrevious(const QString &str , Qt::CaseSensitivity cs);
    22.  
    23. private:
    24. QLabel *label;
    25. QLineEdit *lineEdit;
    26. QCheckBox *caseCheckBox;
    27. QCheckBox *backwardCheckBox;
    28. QPushButton *findButton;
    29. QPushButton *closeButton;
    30.  
    31. private slots:
    32. void findClicked();
    33. void enableFindButton(const QString &text);
    34.  
    35. };
    36. #endif
    To copy to clipboard, switch view to plain text mode 


    main.cpp:

    Qt Code:
    1. #include <QApplication>
    2. #include "test.h"
    3.  
    4. int main(int argc,char *argv[])
    5. {
    6. QApplication app(argc,argv);
    7. FindDialog *fd = new FindDialog;
    8. fd->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


    Please help me about this.
    Thanks
    Last edited by Lykurg; 25th December 2010 at 13:18. Reason: changed [qtclass] to [code]

Similar Threads

  1. Replies: 2
    Last Post: 13th December 2010, 10:31
  2. Signal and Slot Problem
    By waynew in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2010, 10:49
  3. problem connect signal - slot
    By jaca in forum Newbie
    Replies: 13
    Last Post: 9th March 2010, 19:38
  4. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 18:10
  5. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 22:59

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
  •  
Qt is a trademark of The Qt Company.