Results 1 to 11 of 11

Thread: problem with signal/slot mechanismus

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Red face problem with signal/slot mechanismus

    Hello to all, my dear experts!

    I have following line:
    Qt Code:
    1. connect(m_pLeftButtonCaptionInputWidget->ptrTextInput(),
    2. SIGNAL(textChanged()),
    3. this,
    4. SLOT(previewButtonSetText()));
    To copy to clipboard, switch view to plain text mode 
    m_pLeftButtonCaptionInputWidget is declared as follows:
    Qt Code:
    1. #ifndef CDATAINPUTWIDGET_H_
    2. #define CDATAINPUTWIDGET_H_
    3.  
    4. // qt includes
    5. #include <QLabel>
    6. #include <QLineEdit>
    7. #include <QPointer>
    8. #include <QHBoxLayout>
    9. #include <QGroupBox>
    10. #include <QFileDialog>
    11. #include <QStringList>
    12. #include <QPushButton>
    13.  
    14. // forward declarations
    15. class QWidget;
    16. class QString;
    17.  
    18. class CDataInputWidget : public QWidget
    19. {
    20. Q_OBJECT
    21.  
    22. public:
    23. CDataInputWidget(QWidget* pParent=0,
    24. QString strLabelCaption="Caption",
    25. QString strDefaultValue="Caption",
    26. bool boolCheckable=false,
    27. bool boolFileDialog=false);
    28. ~CDataInputWidget();
    29.  
    30. inline QPointer<QHBoxLayout> layout()
    31. { return m_pLayout; };
    32. inline QPointer<QLabel> label()
    33. { return m_pLabel; };
    34. inline QString textInput()
    35. { return m_pTextInput->text(); };
    36. inline QPointer<QLineEdit> ptrTextInput()
    37. { return m_pTextInput; };
    38. inline QPointer<QGroupBox> inputGroupBox()
    39. { return m_pInputGroupBox; };
    40. inline QPointer<QVBoxLayout> mainLayout()
    41. { return m_pMainLayout; };
    42. inline QPointer<QFileDialog> fileDiaog()
    43. { return m_pFileDialog; };
    44. inline QString path()
    45. { return m_strPath; };
    46. inline void setPath(QString strPath)
    47. { m_strPath=strPath; };
    48. inline QPointer<QPushButton> fileBrowserButton()
    49. { return m_pFileBrowserButton; };
    50.  
    51. private:
    52. QPointer<QHBoxLayout> m_pLayout;
    53. QPointer<QLabel> m_pLabel;
    54. QPointer<QLineEdit> m_pTextInput;
    55. QPointer<QGroupBox> m_pInputGroupBox;
    56. QPointer<QVBoxLayout> m_pMainLayout;
    57. QPointer<QFileDialog> m_pFileDialog;
    58. QString m_strPath;
    59. QPointer<QPushButton> m_pFileBrowserButton;
    60.  
    61. private slots:
    62. void showFileBrowser();
    63. };
    64.  
    65. #endif /*CDATAINPUTWIDGET_H_*/
    To copy to clipboard, switch view to plain text mode 
    and its implemenation is:
    Qt Code:
    1. #include "CDataInputWidget.h"
    2.  
    3. CDataInputWidget::CDataInputWidget(QWidget* pParent,
    4. QString strLabelCaption,
    5. QString strDefaultValue,
    6. bool boolCheckable,
    7. bool boolFileDialog)
    8. : QWidget(pParent)
    9. {
    10. m_pMainLayout=new QVBoxLayout(); // creates new layout
    11. Q_CHECK_PTR(m_pMainLayout); // checks creation
    12.  
    13. m_pLayout=new QHBoxLayout(); // creates new layout
    14. Q_CHECK_PTR(m_pLayout); // checks creation
    15.  
    16. m_pLabel=new QLabel(strLabelCaption, this); // creates new label
    17. Q_CHECK_PTR(m_pLabel); // checks creation
    18.  
    19. m_pTextInput=new QLineEdit(strDefaultValue, this); // creates new text input
    20. Q_CHECK_PTR(m_pTextInput); // checks creation
    21.  
    22. m_pLayout->addWidget(m_pLabel); // adds label to layout
    23. m_pLayout->addWidget(m_pTextInput); // adds text input widget
    24.  
    25. m_pInputGroupBox=new QGroupBox(strLabelCaption, this); // creates new gb
    26. Q_CHECK_PTR(m_pInputGroupBox); // checks creation
    27. if (boolCheckable==true)
    28. {
    29. m_pInputGroupBox->setCheckable(true); // toogles check mode
    30. if (boolFileDialog==true)
    31. {
    32. m_pFileBrowserButton=new QPushButton(tr("Browse ..."), this); // creates new button
    33. Q_CHECK_PTR(m_pFileBrowserButton); // checks creation
    34. connect(m_pFileBrowserButton,
    35. SIGNAL(clicked()),
    36. this,
    37. SLOT(showFileBrowser())); // connect click to slot
    38. m_pLayout->addWidget(m_pFileBrowserButton); // addds button to layout
    39. } // if
    40. m_pInputGroupBox->setLayout(m_pLayout); // sets layout
    41. }; // if
    42. m_pMainLayout->addWidget(m_pInputGroupBox); // adds wudget to layout
    43. setLayout(m_pMainLayout);
    44. }
    45.  
    46. CDataInputWidget::~CDataInputWidget()
    47. {
    48. }
    49.  
    50. void CDataInputWidget::showFileBrowser()
    51. {
    52. m_pFileDialog=new QFileDialog(this, tr("Choose picture"),
    53. "images/application",
    54. "*.png"); // creates new file diaog
    55. Q_CHECK_PTR(m_pFileDialog); // checks creation
    56. if(m_pFileDialog->exec())
    57. {
    58. setPath(m_pFileDialog->selectedFiles().at(0));
    59. m_pTextInput->setText(path());
    60. }
    61. }
    To copy to clipboard, switch view to plain text mode 
    Now, here is the problem. Object, instanatiated from this class does not recognize signal textChanged() according to debug output:
    no such signal QTextEdit::textChanged()
    which I need to notify parent object that on text on button has been changed and it the button caption must be updated according to new text.
    Last edited by wysota; 6th March 2008 at 23:08. Reason: Changed [code] to [quote]
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Replies: 2
    Last Post: 20th September 2007, 12:27
  2. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 22:59
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

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.