Drag and Drop Crush when second time drag
Hi forum again me pls help me.
i just want to do that;
ive got two label and i want to drag first label text to drop second label and code worked fine(i dont know why :))). but i want to do this in second time it crushed.
i think i should to clear mimedata but how?? or what i should to do?
here is my . h file
Code:
public:
explicit Dialog
(QWidget *parent
= nullptr
);
~Dialog();
private:
Ui::Dialog *ui;
protected:
and dialog .cpp
Code:
#include <QEvent>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QDebug>
#include <QMouseEvent>
#include <QDrag>
#include <QMimeData>
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->label_2->installEventFilter(this);
ui->label_2->setAcceptDrops(true);
}
Dialog::~Dialog()
{
delete ui;
}
{
if (event->button() == Qt::LeftButton
&& ui->label->geometry().contains(event->pos()))
{
labeltext = ui->label->text();
mimeData->setText(labeltext);
drag->setMimeData(mimeData);
drag->start();
}
}
{
if (event
->type
() == QEvent::DragEnter) {
tDragEnterEvent->acceptProposedAction();
return true;
}
else if (event
->type
() == QEvent::DragMove) {
QDragMoveEvent *tDragMoveEvent
= static_cast<QDragMoveEvent
*>
(event
);
tDragMoveEvent->acceptProposedAction();
return true;
}
else if (event
->type
() == QEvent::Drop) {
QDropEvent *tDropEvent
= static_cast<QDropEvent
*>
(event
);
tDropEvent->acceptProposedAction();
ui->label_2->setText(mimeData->text());
return true;
}
return QObject::eventFilter(obj, event
);
}
please help mee pleeeeaseeeee :((
(and pls i dont want to use subclass for this)
Re: Drag and Drop Crush when second time drag
A crash is usually a good source to find what is wrong, e.g. by running the program in debugger and checking which call causes the crash.
Especially if you have a reliable way of triggering the crash.
Educated guess: the second time calls methods on a now invalid QDrag pointer.
Cheers,
_
Re: Drag and Drop Crush when second time drag
All my respect sir,
What am i doing please show me the way
Re: Drag and Drop Crush when second time drag
1) Compile the program in debug mode
2) Run the program in the debugger
3) Check where it crashes
Debugging a crash is the most fundamental thing to learn.
Telling you the cause and/or solution for this specific crash does not help you in the long run
Cheers,
_
Re: Drag and Drop Crush when second time drag
Quote:
Educated guess: the second time calls methods on a now invalid QDrag pointer.
And probably an invalid QMimeData pointer as well, since QDrag::setMimeData() takes ownership and if the QDrag instance is destroyed, so will be the QMimeData instance.
I can't find a QDrag:: start() method, so where did this come from, and how did you get the code to compile in the first place?
Re: Drag and Drop Crush when second time drag
Quote:
Originally Posted by
d_stranz
And probably an invalid QMimeData pointer as well, since
QDrag::setMimeData() takes ownership and if the QDrag instance is destroyed, so will be the QMimeData instance.
Yep
Quote:
Originally Posted by
d_stranz
I can't find a QDrag:: start() method, so where did this come from, and how did you get the code to compile in the first place?
Deprecated and thus not part of the API documentation.
But still in the header.
Cheers,
_