QWidget: Cannot create a QWidget without QApplication

参考博客:https://blog.csdn.net/lsxpu/article/details/17840231

产生这个错误的原因是这个QWidget 是建立在QApplication 上的,(From the docs, the QApplication class manages the GUI application's control flow and main settings whilst the QCoreApplication class provides an event loop for console Qt applications),改成下面的代码就行了:

#include <QCoreApplication>
#include <QApplication>
#include <QWidget>

int main(int argc, char *argv[])
{
//    QCoreApplication a(argc, argv);
    QApplication a(argc, argv);
    QWidget *music_player_widget=new QWidget();
    music_player_widget->show();
    return a.exec();
}

文章目录