1

我遇到了非常奇怪的问题。我正在使用 VLCQt 库并成功运行了一个非常简单的视频播放器。但是当我想在主类中添加一个非常简单的 Qlabel 时,它会在此时崩溃ui->setupUi(this)。输出窗口包含以下语句:

HEAP[VideoPlayer.exe]:指定给 RtlValidateHeap(00000000002F0000, 0000000000334220) 的地址无效 VideoPlayer.exe 已触发断点。

简单播放器.h:

class SimplePlayer : public QMainWindow
{
     Q_OBJECT

    public:
    SimplePlayer(QWidget *parent = 0);
    ~SimplePlayer();

    private:
    Ui::SimplePlayer *ui;
    VlcInstance *_instance;
    VlcMedia *_media;
    VlcMediaPlayer *_player;
    //QLabel *_lbl;//  if I declare a very simple Qlabel the app crashes

    private slots:
    void openLocal();
    void openUrl();
 };

简单播放器.cpp

  SimplePlayer::SimplePlayer(QWidget *parent)
: QMainWindow(parent)
{
    ui->setupUi(this);
   _instance = new VlcInstance(VlcCommon::args(), this);
   _player = new VlcMediaPlayer(_instance);
   _player->setVideoWidget(ui->video);
    ui->video->setMediaPlayer(_player);
    ui->volume->setMediaPlayer(_player);
    ui->volume->setVolume(50);
    ui->seek->setMediaPlayer(_player);
   // _lbl = new QLabel;//  if I declare a very simple Qlabel the app crashes
    ...//connections

}
4

1 回答 1

0

你永远不会设置你的ui类成员,所以你调用setupUi(this);的是一个空指针。

您需要使您的成员成为值而不是指针:

private:
    Ui::SimplePlayer ui;

或者您需要在构造函数的开头创建一个 SimplePlayer:

ui = new Ui::SimplePlayer();
于 2017-11-30T21:47:13.403 回答