1

I faced very strange problem.I am using VLCQt library and successfully run a very simple videoplayer. but when I want to add a very simple Qlabel to the main class, It crashes at this point ui->setupUi(this). the output window contains these statament:

HEAP[VideoPlayer.exe]: Invalid address specified to RtlValidateHeap( 00000000002F0000, 0000000000334220 ) VideoPlayer.exe has triggered a breakpoint.

SimplePlayer.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();
 };

SimplePlayer.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

}
Atefe
  • 33
  • 6
  • 1
    Are you sure you are using the correct binaries for your compiler (and correct configuration)? Using binaries compiled for a different compiler version or mixing debug and release with Visual Studio will cause heap corruption problems. – drescherjm Nov 30 '17 at 18:46

1 Answers1

0

You are never setting your ui class member, so you are calling setupUi(this); on a null pointer.

You need to either make your member a value and not a pointer:

private:
    Ui::SimplePlayer ui;

Or you need to create a SimplePlayer at the beginning of your constructor:

ui = new Ui::SimplePlayer();
Atlante45
  • 333
  • 1
  • 10
  • thanks. the problem was fixed. But the crash was just after declaring the new QLabel . why it was working fine before? – Atefe Dec 01 '17 at 07:03
  • Are you sure it wasn't crashing before you had the QLabel? There is no way `ui->setupUi(this);` wasn't crashing your program if you left `ui` to `null`. – Atlante45 Dec 01 '17 at 22:02
  • Yes. it worked fine before. anyway the problem was fixed. thanks a lot – Atefe Dec 07 '17 at 08:45