对着书练习出现错误...
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>class QTextEdit;class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0);protected: void dragEnterEvent(QDragEnterEvent *); void dropEvent(QDropEvent *);private: bool readFile(const QString &fileName); QTextEdit *textEdit;signals:public slots:};#endif // MAINWINDOW_H
#include<QtGui>#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ textEdit = new QTextEdit; setCentralWidget(textEdit); textEdit->setAcceptDrops(false); setAcceptDrops(true); setWindowTitle(tr("Text Rditor"));}void MainWindow::dragEnterEvent(QDragEnterEvent * event){ if(event->mimeData()->hasFormat("text/uri-list")) event->acceptProposedAction();}void MainWindow::dropEvent(QDropEvent * event){ QList<QUrl> urls=event->mimeData()->urls(); if(urls.isEmpty()) return; QString fileName=urls.first().toLocalFile(); if(fileName.isEmpty()) return; if(readFile(fileName)) setWindowTitle(tr("%1-%2").arg(fileName).arg(tr("Drag File")));}