Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Problem with const in dragMoveEvent

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

Viewing all articles
Browse latest Browse all 18427

Trending Articles