Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Solved: Problem with const in dragMoveEvent
Forum Updated to NodeBB v4.3 + New Features

Solved: Problem with const in dragMoveEvent

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    I'm a beginner and struggling with const, so I'm hoping someone here can help me "over the hump". I am trying to subclass QTextEdit to intercept a drag from a QListWidget. I need to determine what the text is in the QListItem and set the QMimeData data to text/plain. Here is what I have so far:

    @void TextEditDrop::dragEnterEvent(QDragEnterEvent *e)
    {
    const QMimeData *mimeData = e->mimeData();
    QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist");
    QDataStream stream(&encoded, QIODevice::ReadOnly);
    QString item;
    int row, col;
    QMap<int, QVariant> roleDataMap;
    while (!stream.atEnd())
    {
    stream >> row >> col >> roleDataMap;
    item = roleDataMap.value( Qt::DisplayRole ).toString();
    }

    // Next statement generates error
    // error: C2662: 'QMimeData::setText' : cannot convert 'this' pointer from 
    //               'const QMimeData' to 'QMimeData &'
    mimeData->setText(item);
    
    // this also does not work:
    mimeData->setText(const_cast<QString>(item));  // cannot convert from QString to QString
    

    }@

    I believe I have to const_cast item but I have not been able to discover a syntax that works. Any help much appreciated.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      First of all you need to perform your operations in dropEvent(), Secondly why are you using const QMimeData you can use QMimeData instead.

      Check "Drag and Drop Puzzle Example":http://qt-project.org/doc/qt-4.8/draganddrop-puzzle.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rory_1
        wrote on last edited by
        #3

        Thanks. I'll check out the example.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rory_1
          wrote on last edited by
          #4

          I solved this issue by subclassing QListWidget::startDrag and creating a QMimeData->setText.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved