You are not logged in.

  • "gajendersingh" is male
  • "gajendersingh" started this thread

Posts: 34

Location: India

Occupation: IT

  • Send private message

1

Wednesday, August 8th 2007, 8:03am

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

King Nak

Trainee

  • "King Nak" is male

Posts: 89

Location: Austria

  • Send private message

2

Wednesday, August 8th 2007, 8:42am

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

  • "gajendersingh" is male
  • "gajendersingh" started this thread

Posts: 34

Location: India

Occupation: IT

  • Send private message

3

Wednesday, August 8th 2007, 8:57am

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

ct313

Trainee

  • "ct313" is male

Posts: 127

Location: Viet Nam

Occupation: Software Developer

  • Send private message

4

Wednesday, August 8th 2007, 12:20pm

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 !!!

  • "gajendersingh" is male
  • "gajendersingh" started this thread

Posts: 34

Location: India

Occupation: IT

  • Send private message

5

Wednesday, August 8th 2007, 12:50pm

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

ct313

Trainee

  • "ct313" is male

Posts: 127

Location: Viet Nam

Occupation: Software Developer

  • Send private message

6

Wednesday, August 8th 2007, 3:49pm

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 !!!

  • "gajendersingh" is male
  • "gajendersingh" started this thread

Posts: 34

Location: India

Occupation: IT

  • Send private message

7

Thursday, August 9th 2007, 4:52am

RE: Trigger an signal when drop is carried out.

Quoted

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

huzefar

Trainee

  • "huzefar" is male

Posts: 101

Location: London, UK

Occupation: software engineer

  • Send private message

8

Thursday, August 9th 2007, 4:18pm

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...