-
UID:153835
-
- 注册时间2014-07-09
- 最后登录2017-09-14
- 在线时间31小时
-
- 发帖14
- 搜Ta的帖子
- 精华0
- 金钱170
- 威望27
- 贡献值0
- 好评度17
-
访问TA的空间加好友用道具
|
mymwin.h - class MyTextEdit : public QTextEdit
- {
- Q_OBJECT
- public:
- MyTextEdit(QWidget *parent = 0);
- ~MyTextEdit();
- protected:
- void dragEnterEvent(QDragEnterEvent *);
- void dropEvent(QDropEvent *);
- };
- class MyMWin : public QMainWindow
- {
- Q_OBJECT
- public:
- MyMWin(QWidget *parent = 0);
- ~MyMWin();
- ......
- private:
- ......
- MyTextEdit *text;
- ......
- };
mymwin.cpp - void MyTextEdit::dropEvent(QDropEvent *event)
- {
- qDebug()<<"enter dropEvent"<<endl;
- const QMimeData *mimeData=event->mimeData();
- if(mimeData->hasUrls())
- {
- QList<QUrl> url=mimeData->urls();
- QString fileName=url[0].toLocalFile();
- qDebug()<<"fileName:"<<fileName<<endl;
- if(!fileName.isEmpty())
- {
- QFile file(fileName);
- if(!file.open(QIODevice::ReadOnly)) return;
- QTextStream in(&file);
- //这里想使用类MyMwin的text成员,应该怎样使用呢
- }
- }
- else
- event->ignore();
- }
main.cpp - #include "mymwin.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MyMWin w;
- w.show();
- return a.exec();
- }
|