Hello to all, my dear experts!
I have following line:
connect(m_pLeftButtonCaptionInputWidget->ptrTextInput(),
SIGNAL(textChanged()),
this,
SLOT(previewButtonSetText()));
connect(m_pLeftButtonCaptionInputWidget->ptrTextInput(),
SIGNAL(textChanged()),
this,
SLOT(previewButtonSetText()));
To copy to clipboard, switch view to plain text mode
m_pLeftButtonCaptionInputWidget is declared as follows:
#ifndef CDATAINPUTWIDGET_H_
#define CDATAINPUTWIDGET_H_
// qt includes
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QFileDialog>
#include <QStringList>
#include <QPushButton>
// forward declarations
class CDataInputWidget
: public QWidget{
Q_OBJECT
public:
CDataInputWidget
(QWidget* pParent
=0,
bool boolCheckable=false,
bool boolFileDialog=false);
~CDataInputWidget();
inline QPointer<QHBoxLayout> layout()
{ return m_pLayout; };
inline QPointer<QLabel> label()
{ return m_pLabel; };
{ return m_pTextInput->text(); };
inline QPointer<QLineEdit> ptrTextInput()
{ return m_pTextInput; };
inline QPointer<QGroupBox> inputGroupBox()
{ return m_pInputGroupBox; };
inline QPointer<QVBoxLayout> mainLayout()
{ return m_pMainLayout; };
inline QPointer<QFileDialog> fileDiaog()
{ return m_pFileDialog; };
{ return m_strPath; };
inline void setPath
(QString strPath
) { m_strPath=strPath; };
inline QPointer<QPushButton> fileBrowserButton()
{ return m_pFileBrowserButton; };
private:
QPointer<QHBoxLayout> m_pLayout;
QPointer<QLabel> m_pLabel;
QPointer<QLineEdit> m_pTextInput;
QPointer<QGroupBox> m_pInputGroupBox;
QPointer<QVBoxLayout> m_pMainLayout;
QPointer<QFileDialog> m_pFileDialog;
QPointer<QPushButton> m_pFileBrowserButton;
private slots:
void showFileBrowser();
};
#endif /*CDATAINPUTWIDGET_H_*/
#ifndef CDATAINPUTWIDGET_H_
#define CDATAINPUTWIDGET_H_
// qt includes
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QFileDialog>
#include <QStringList>
#include <QPushButton>
// forward declarations
class QWidget;
class QString;
class CDataInputWidget : public QWidget
{
Q_OBJECT
public:
CDataInputWidget(QWidget* pParent=0,
QString strLabelCaption="Caption",
QString strDefaultValue="Caption",
bool boolCheckable=false,
bool boolFileDialog=false);
~CDataInputWidget();
inline QPointer<QHBoxLayout> layout()
{ return m_pLayout; };
inline QPointer<QLabel> label()
{ return m_pLabel; };
inline QString textInput()
{ return m_pTextInput->text(); };
inline QPointer<QLineEdit> ptrTextInput()
{ return m_pTextInput; };
inline QPointer<QGroupBox> inputGroupBox()
{ return m_pInputGroupBox; };
inline QPointer<QVBoxLayout> mainLayout()
{ return m_pMainLayout; };
inline QPointer<QFileDialog> fileDiaog()
{ return m_pFileDialog; };
inline QString path()
{ return m_strPath; };
inline void setPath(QString strPath)
{ m_strPath=strPath; };
inline QPointer<QPushButton> fileBrowserButton()
{ return m_pFileBrowserButton; };
private:
QPointer<QHBoxLayout> m_pLayout;
QPointer<QLabel> m_pLabel;
QPointer<QLineEdit> m_pTextInput;
QPointer<QGroupBox> m_pInputGroupBox;
QPointer<QVBoxLayout> m_pMainLayout;
QPointer<QFileDialog> m_pFileDialog;
QString m_strPath;
QPointer<QPushButton> m_pFileBrowserButton;
private slots:
void showFileBrowser();
};
#endif /*CDATAINPUTWIDGET_H_*/
To copy to clipboard, switch view to plain text mode
and its implemenation is:
#include "CDataInputWidget.h"
CDataInputWidget
::CDataInputWidget(QWidget* pParent,
bool boolCheckable,
bool boolFileDialog)
{
Q_CHECK_PTR(m_pMainLayout); // checks creation
Q_CHECK_PTR(m_pLayout); // checks creation
m_pLabel
=new QLabel(strLabelCaption,
this);
// creates new label Q_CHECK_PTR(m_pLabel); // checks creation
m_pTextInput
=new QLineEdit(strDefaultValue,
this);
// creates new text input Q_CHECK_PTR(m_pTextInput); // checks creation
m_pLayout->addWidget(m_pLabel); // adds label to layout
m_pLayout->addWidget(m_pTextInput); // adds text input widget
m_pInputGroupBox
=new QGroupBox(strLabelCaption,
this);
// creates new gb Q_CHECK_PTR(m_pInputGroupBox); // checks creation
if (boolCheckable==true)
{
m_pInputGroupBox->setCheckable(true); // toogles check mode
if (boolFileDialog==true)
{
m_pFileBrowserButton
=new QPushButton(tr
("Browse ..."),
this);
// creates new button Q_CHECK_PTR(m_pFileBrowserButton); // checks creation
connect(m_pFileBrowserButton,
SIGNAL(clicked()),
this,
SLOT(showFileBrowser())); // connect click to slot
m_pLayout->addWidget(m_pFileBrowserButton); // addds button to layout
} // if
m_pInputGroupBox->setLayout(m_pLayout); // sets layout
}; // if
m_pMainLayout->addWidget(m_pInputGroupBox); // adds wudget to layout
setLayout(m_pMainLayout);
}
CDataInputWidget::~CDataInputWidget()
{
}
void CDataInputWidget::showFileBrowser()
{
m_pFileDialog
=new QFileDialog(this, tr
("Choose picture"),
"images/application",
"*.png"); // creates new file diaog
Q_CHECK_PTR(m_pFileDialog); // checks creation
if(m_pFileDialog->exec())
{
setPath(m_pFileDialog->selectedFiles().at(0));
m_pTextInput->setText(path());
}
}
#include "CDataInputWidget.h"
CDataInputWidget::CDataInputWidget(QWidget* pParent,
QString strLabelCaption,
QString strDefaultValue,
bool boolCheckable,
bool boolFileDialog)
: QWidget(pParent)
{
m_pMainLayout=new QVBoxLayout(); // creates new layout
Q_CHECK_PTR(m_pMainLayout); // checks creation
m_pLayout=new QHBoxLayout(); // creates new layout
Q_CHECK_PTR(m_pLayout); // checks creation
m_pLabel=new QLabel(strLabelCaption, this); // creates new label
Q_CHECK_PTR(m_pLabel); // checks creation
m_pTextInput=new QLineEdit(strDefaultValue, this); // creates new text input
Q_CHECK_PTR(m_pTextInput); // checks creation
m_pLayout->addWidget(m_pLabel); // adds label to layout
m_pLayout->addWidget(m_pTextInput); // adds text input widget
m_pInputGroupBox=new QGroupBox(strLabelCaption, this); // creates new gb
Q_CHECK_PTR(m_pInputGroupBox); // checks creation
if (boolCheckable==true)
{
m_pInputGroupBox->setCheckable(true); // toogles check mode
if (boolFileDialog==true)
{
m_pFileBrowserButton=new QPushButton(tr("Browse ..."), this); // creates new button
Q_CHECK_PTR(m_pFileBrowserButton); // checks creation
connect(m_pFileBrowserButton,
SIGNAL(clicked()),
this,
SLOT(showFileBrowser())); // connect click to slot
m_pLayout->addWidget(m_pFileBrowserButton); // addds button to layout
} // if
m_pInputGroupBox->setLayout(m_pLayout); // sets layout
}; // if
m_pMainLayout->addWidget(m_pInputGroupBox); // adds wudget to layout
setLayout(m_pMainLayout);
}
CDataInputWidget::~CDataInputWidget()
{
}
void CDataInputWidget::showFileBrowser()
{
m_pFileDialog=new QFileDialog(this, tr("Choose picture"),
"images/application",
"*.png"); // creates new file diaog
Q_CHECK_PTR(m_pFileDialog); // checks creation
if(m_pFileDialog->exec())
{
setPath(m_pFileDialog->selectedFiles().at(0));
m_pTextInput->setText(path());
}
}
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.
Bookmarks