Qt错误:在此范围内未声明`qApp'

Ash*_*hot 7 c++ qt

据我所知,qApp是全局指针,因此它应该可以在任何地方访问,但我收到此错误 error: qApp was not declared in this scope.

  1 #include "textEdit.h"
  2
  3 TextEdit::TextEdit() {
  4 }
  5
  6 void TextEdit::insertFromMimeData (const QMimeData * source) {
  7     if (qApp->mouseButtons() == Qt::MidButton) {
  8         return;
  9     }
 10     QTextEdit::insertFromMimeData(source);
 11 }
 12
 13
Run Code Online (Sandbox Code Playgroud)

Muc*_*ewe 12

你需要使用

#include <QApplication>
Run Code Online (Sandbox Code Playgroud)

使用qApp宏.请参阅http://doc.qt.io/qt-5/qapplication.html#qApp上的文档


Joh*_*hny 6

您可能忘记在声明中包含标头。

 #include <QApplication>
Run Code Online (Sandbox Code Playgroud)