Hello,
we have a bit problem with qobject_cast.
{
Touchpad *myTouchpad;
QLineEdit *isQLineEdit
= qobject_cast<QLineEdit
*>
(call_object
);
if (pevent
->type
() == QEvent::MouseButtonPress) {
}
}
bool MyDialog::eventFilter(QObject* call_object, QEvent* pevent)
{
Touchpad *myTouchpad;
QLineEdit *isQLineEdit = qobject_cast<QLineEdit*>(call_object);
if (pevent->type() == QEvent::MouseButtonPress)
{
}
}
To copy to clipboard, switch view to plain text mode
mydialog.cpp: In member function ‘virtual bool MyDialog::eventFilter(QObject*, QEvent*)’:
mydialog.cpp:540: error: ‘qobject_cast’ was not declared in this scope
mydialog.cpp:540: error: expected primary-expression before ‘*’ token
mydialog.cpp:540: error: expected primary-expression before ‘>’ token
But If I use this code...
{
Touchpad *myTouchpad;
QLineEdit *isQLineEdit
= static_cast<QLineEdit
*>
(call_object
);
if(!isQLineEdit) return false; // Si no se trata de un QLineEdit, no se hace nada
if (pevent
->type
() == QEvent::MouseButtonPress) {
myTouchpad = new Touchpad(isQLineEdit,0,TRUE,WStyle_Customize | WStyle_NoBorder);
myTouchpad->txt_dato->setText(isQLineEdit->text());
myTouchpad->show();
return true;
}else
return false;
}
bool MyDialog::eventFilter(QObject* call_object, QEvent* pevent)
{
Touchpad *myTouchpad;
QLineEdit *isQLineEdit = static_cast<QLineEdit*>(call_object);
if(!isQLineEdit) return false; // Si no se trata de un QLineEdit, no se hace nada
if (pevent->type() == QEvent::MouseButtonPress)
{
myTouchpad = new Touchpad(isQLineEdit,0,TRUE,WStyle_Customize | WStyle_NoBorder);
myTouchpad->txt_dato->setText(isQLineEdit->text());
myTouchpad->show();
return true;
}else
return false;
}
To copy to clipboard, switch view to plain text mode
the application works fine. So, the question is, what is the difference between static_cast and qobject_cast??
Best regards.
Bookmarks