• 2624阅读
  • 1回复

关于成员访问 [复制链接]

上一主题 下一主题
离线wxxzs123
 

只看楼主 倒序阅读 楼主  发表于: 2014-08-15
mymwin.h
  1. class MyTextEdit : public QTextEdit
  2. {
  3.     Q_OBJECT
  4. public:
  5.     MyTextEdit(QWidget *parent = 0);
  6.     ~MyTextEdit();
  7. protected:
  8.     void dragEnterEvent(QDragEnterEvent *);
  9.     void dropEvent(QDropEvent *);
  10. };
  11. class MyMWin : public QMainWindow
  12. {
  13.     Q_OBJECT
  14. public:
  15.     MyMWin(QWidget *parent = 0);
  16.     ~MyMWin();
  17.     ......
  18. private:
  19.     ......
  20.     MyTextEdit *text;
  21.     ......
  22. };

mymwin.cpp
  1. void MyTextEdit::dropEvent(QDropEvent *event)
  2. {
  3.     qDebug()<<"enter dropEvent"<<endl;
  4.     const QMimeData *mimeData=event->mimeData();
  5.     if(mimeData->hasUrls())
  6.     {
  7.         QList<QUrl> url=mimeData->urls();
  8.         QString fileName=url[0].toLocalFile();
  9.         qDebug()<<"fileName:"<<fileName<<endl;
  10.         if(!fileName.isEmpty())
  11.         {
  12.             QFile file(fileName);
  13.             if(!file.open(QIODevice::ReadOnly)) return;
  14.             QTextStream in(&file);
  15.             //这里想使用类MyMwin的text成员,应该怎样使用呢
  16.         }
  17.     }
  18.     else
  19.         event->ignore();
  20. }

main.cpp
  1. #include "mymwin.h"
  2. #include <QApplication>
  3. int main(int argc, char *argv[])
  4. {
  5.     QApplication a(argc, argv);
  6.     MyMWin w;
  7.     w.show();
  8.     return a.exec();
  9. }


离线wxxzs123

只看该作者 1楼 发表于: 2014-08-15
是不是要把text改成公有成员
快速回复
限100 字节
 
上一个 下一个