Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.
Trigger an signal when drop is carried out.
I am trying to emit an signal() inside an dropevent() and i am getting error
"protected: void __thiscall ImageArea::imageObjectDroped(void)" (?imageObjectDroped@ImageArea@@IAEXXZ) referenced in function "public: virtual void __thiscall ImageArea::dropEvent(class QDropEvent *)" (?dropEvent@ImageArea@@UAEXPAVQDropEvent@@@Z)"
what exactly i want to do is i trigger an singnal when drop is carred out on child widget.
class MyWindow : public QWidget
{
Q_OBJECT // Enable signals and slots
public:
MyWindow();
void dropEvent(QDropEvent *event);
signals:
void created();
};
can i do this or can there be an work arround.
---
Gajender Singh
RE: Trigger an signal when drop is carried out.
There is no problem with emitting the signal. It seems like you have not implemented
void ImageArea::imageObjectDroped().
bye
King Nak
RE: Trigger an signal when drop is carried out.
what piece of code do i need to write in void ImageArea::imageObjectDroped(), do i need to write connect here, or some thing else.
---
Gajender Singh
RE: Trigger an signal when drop is carried out.
Hi,
you can emit signal when you droped object.
and catch it when you need.
When you believe in yourself, the other can be your !!!
RE: Trigger an signal when drop is carried out.
I am sending along code.... this piece of code dont call CallbackImageObjectDroped() function of parent.... if any modifications are needed then please do tell me....
class ImageArea : public QLabel
{
public:
ImageArea(QWidget *parent);
signals:
void imageObjectDroped();
private:
void dropEvent(QDropEvent *event);
};
ImageArea::ImageArea(QWidget *parent): QLabel(parent)
{
setAcceptDrops(true);
connect(this, SIGNAL(imageObjectDroped()), parent, SLOT(CallbackImageObjectDroped()));
}
void ImageArea::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("application/x -Image")) {
emit imageObjectDroped();
} else {
event->ignore();
}
}
void ImageArea::imageObjectDroped()
{
}
---
Gajender Singh
RE: Trigger an signal when drop is carried out.
Hi,
Your code:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
|
void ImageArea::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("application/x -Image"))
{
emit imageObjectDroped();
}
else
{
event->ignore();
}
}
|
Why you must check
|
Source code
|
1
|
if (event->mimeData()->hasFormat("application/x -Image"))
|
you can emit signal without "if"
|
Source code
|
1
2
3
4
|
void ImageArea::dropEvent(QDropEvent *event)
{
emit imageObjectDroped();
}
|
I think problem of you is your code not right.
When you believe in yourself, the other can be your !!!
RE: Trigger an signal when drop is carried out.
if (event->mimeData()->hasFormat("application/x -Image"))
this won't cause any problem as this is just an check for a specified drop format and i want ot emit signal only when a specified format of data is droped, i dont want this to happen for all drop types....
---
Gajender Singh
Well from your code it looks member are not provided proper scoping
for example:
private:
void dropEvent(QDropEvent *event);
you have declared your drop event as private. It should be virtual protected. This is imp coz u have inherited ur class from qwidget and you are trying to override the dropEvent of the base class .
Try that and it should work. As you said .. their is no probs with your if () condition
hope that helps
cheers
huzy
Regards
Huzy...