PDA

View Full Version : How to create a QT application that uses BASS library (un4seen)?



Rainer78
1st February 2013, 18:04
Hi @ all,

after several problems building the new QT5 with MinGW for X64 on Windows 7, it finally works.

Now I want to play a simple mp3 file. the QMediaPlayer ssems to require a lot of system resources, so I am trying some different librarys.

My development enviroment is the QT Creator and I have the following directories:

c:\qt\qt5 (containing the compiled QT5 directories like qtbase etc)
c:\qt\mingw64-4.7.2 (including the bin / lib / include etc directories)

I have downloaded the BASS for 64bit from here http://www.un4seen.com/forum/?topic=9038

I have added the following lines to my .pro file


win32: LIBS += -L$$PWD/lib/ -lbass

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/


The "lib" folder contains only the bass.lib file. The bass.dll is in the compiler output directory (there where the created exe file will be created).

In the constructor of my dialog I have the following code:


....
#include "bass.h"
....
....
Player::Player(QWidget *parent) :
QDialog(parent),
ui(new Ui::Player)
{
int mybassVersion;
mybassVersion = BASS_GetVersion();
if (mybassVersion!=BASSVERSION) {
QMessageBox msgBox;
msgBox.setText("An incorrect version of BASS.DLL was loaded");
msgBox.exec();
}
....
}


But everytime I start the program, the program terminated with an "Segmentation fault" message. :(

I haven't started with writing the source code I want (to play an MP3 file) because the "basic functions" doesn't work.

Can someone help me to get this simple program run?

Maybe someone has a little demo application of how to use the BASS library with the QT creator.

Thank you very much.

Best regards,

Rainer

d_stranz
1st February 2013, 18:32
This isn't really a Qt question, and you haven't shown enough code to diagnose where the error might be. It is probably completely unrelated to this BASS library and is most likely something you are doing wrong elsewhere.

Have you actually stepped into your code using the debugger to find out where the segmentation fault occurs? Or you simply running the program and watching it fail?

Rainer78
1st February 2013, 20:11
I know, that this is not a direct Qt question. Sorry.

Here is my code:

bassTest.pro

#-------------------------------------------------
#
# Project created by QtCreator 2013-02-01T20:52:02
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = bassTest
TEMPLATE = app


SOURCES += main.cpp\
dialog.cpp

HEADERS += dialog.h\
bass.h

FORMS += dialog.ui

win32: LIBS += -L$$PWD/lib/ -lbass

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/


dialog.cpp

#include "dialog.h"
#include "ui_dialog.h"
#include "bass.h"
#include <QMessageBox>

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QMessageBox msgBox;

if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
msgBox.setText("An incorrect version of BASS.DLL was loaded");
}
else {
msgBox.setText("A correct version of BASS.DLL was loaded");
}

msgBox.exec();

}

Dialog::~Dialog()
{
delete ui;
}



The error occurs during while using the debugger in line 13.


if (HIWORD(BASS_GetVersion())!=BASSVERSION) {


A correct base.dll is in the same folder like the exe-file.

Any ideas?

I have attached the complete sourcecode as a zip file.

d_stranz
1st February 2013, 20:41
In bass.h there is at least one method that looks to be a prerequisite for any operations using the library:


HPLUGIN BASSDEF(BASS_PluginLoad)( const char * file, DWORD flags );

Perhaps you should start by reading the BASS documentation and looking at any example programs that might be in either your downloaded code or on the library's web site.

Edit: Maybe I am wrong about that - this function may just be for loading plugins for use with BASS, not the BASS library itself. In a simple example from the BASS distribution, the WinMain() method does exactly what you are doing:



int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
// check the correct BASS was loaded
if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
MessageBox(0,"An incorrect version of BASS.DLL was loaded",0,MB_ICONERROR);
return 0;
}

// display the window
DialogBox(hInstance,MAKEINTRESOURCE(1000),NULL,&dialogproc);

return 0;
}


So my guess is that you might be linking a release version of the library to the debug version of the executable. This generally doesn't work in Windoze.