Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSound global object bug
Forum Updated to NodeBB v4.3 + New Features

QSound global object bug

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 856 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cpper
    wrote on 12 Aug 2016, 21:06 last edited by cpper 8 Dec 2016, 21:10
    #1

    This is a fresh project, only lines added are lines 4 and 5.
    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QSound>
    QSound notif("notif.wav");
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    I've added QT= multimedia in the .pro file and am sure that "notif.wav" is in the right folder. When compiling, I get some strange errors: When I first click on run, the window opens, and I don't get any error. I close the program and click again run, I get runtime error: "Debug Error ! R6010 -abort() has been called". I click on abort, click again on run, and this time I get output "test.exe exited with code 255". Click one more time on run, an get output "The program has unexpectedly finished" "test.exe" crashed.

    This is the output when I get the runtime error:
    QThread::wait: Thread tried to wait on itself
    QCoreApplication::postEvent: Unexpected null receiver
    QThread: Destroyed while thread is still running
    QMutex: destroying locked mutex
    QMutex: destroying locked mutex
    C:\Users\User\Documents\build-test2-Desktop_Qt_5_7_0_MSVC2013_64bit-Debug\debug\test2.exe exited with code 3."

    So I get 4 different error without changing anything in the code. What's wrong ?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 12 Aug 2016, 21:19 last edited by A Former User 8 Dec 2016, 21:21
      #2

      Hi! QSound inherits from QObject. You must not create any QObject before the QApplication object has been created. Also all QObjects must be destroyed before the QApplication object gets destroyed. In other words: Don't use global / static QObjects or you'll experience undefined behaviour.

      C 1 Reply Last reply 12 Aug 2016, 21:23
      2
      • ? A Former User
        12 Aug 2016, 21:19

        Hi! QSound inherits from QObject. You must not create any QObject before the QApplication object has been created. Also all QObjects must be destroyed before the QApplication object gets destroyed. In other words: Don't use global / static QObjects or you'll experience undefined behaviour.

        C Offline
        C Offline
        cpper
        wrote on 12 Aug 2016, 21:23 last edited by
        #3

        @Wieland
        Oh, thanks, didn't knew that.

        1 Reply Last reply
        0

        1/3

        12 Aug 2016, 21:06

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved