Results 1 to 6 of 6

Thread: Drag and Drop Crush when second time drag

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2019
    Posts
    5
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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
    Qt Code:
    1. public:
    2. explicit Dialog(QWidget *parent = nullptr);
    3. ~Dialog();
    4. void mousePressEvent(QMouseEvent *event) ;
    5. QDrag *drag = new QDrag(this);
    6. QMimeData *mimeData = new QMimeData;
    7. QString labeltext;
    8.  
    9.  
    10. private:
    11. Ui::Dialog *ui;
    12.  
    13. protected:
    14. bool eventFilter(QObject *obj, QEvent *event);
    To copy to clipboard, switch view to plain text mode 

    and dialog .cpp
    Qt Code:
    1. #include <QEvent>
    2. #include <QDragEnterEvent>
    3. #include <QDragMoveEvent>
    4. #include <QDropEvent>
    5. #include <QDebug>
    6. #include <QMouseEvent>
    7. #include <QDrag>
    8. #include <QMimeData>
    9.  
    10. Dialog::Dialog(QWidget *parent) :
    11. QDialog(parent),
    12. ui(new Ui::Dialog)
    13. {
    14. ui->setupUi(this);
    15. ui->label_2->installEventFilter(this);
    16. ui->label_2->setAcceptDrops(true);
    17. }
    18.  
    19. Dialog::~Dialog()
    20. {
    21. delete ui;
    22. }
    23.  
    24. void Dialog::mousePressEvent(QMouseEvent *event)
    25. {
    26. if (event->button() == Qt::LeftButton
    27. && ui->label->geometry().contains(event->pos()))
    28. {
    29.  
    30. labeltext = ui->label->text();
    31.  
    32. mimeData->setText(labeltext);
    33. drag->setMimeData(mimeData);
    34. drag->start();
    35. }
    36. }
    37.  
    38. bool Dialog::eventFilter(QObject *obj, QEvent *event)
    39. {
    40. if (event->type() == QEvent::DragEnter)
    41. {
    42. QDragEnterEvent *tDragEnterEvent = static_cast<QDragEnterEvent *>(event);
    43. tDragEnterEvent->acceptProposedAction();
    44.  
    45. return true;
    46. }
    47.  
    48. else if (event->type() == QEvent::DragMove)
    49. {
    50. QDragMoveEvent *tDragMoveEvent = static_cast<QDragMoveEvent *>(event);
    51. tDragMoveEvent->acceptProposedAction();
    52.  
    53. return true;
    54. }
    55.  
    56.  
    57. else if (event->type() == QEvent::Drop)
    58. {
    59. QDropEvent *tDropEvent = static_cast<QDropEvent *>(event);
    60. tDropEvent->acceptProposedAction();
    61.  
    62. ui->label_2->setText(mimeData->text());
    63.  
    64.  
    65. return true;
    66. }
    67.  
    68. return QObject::eventFilter(obj, event);
    69. }
    To copy to clipboard, switch view to plain text mode 
    please help mee pleeeeaseeeee :((

    (and pls i dont want to use subclass for this)
    Last edited by anda_skoa; 23rd February 2019 at 12:18. Reason: missing [code] tags

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2014, 06:46
  2. Replies: 0
    Last Post: 7th January 2012, 15:20
  3. Replies: 2
    Last Post: 13th October 2010, 21:51
  4. Replies: 3
    Last Post: 10th June 2010, 15:13
  5. Replies: 0
    Last Post: 4th May 2010, 10:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.