Calling function from dll with QT

Jack

I created by the first time a dll to use with C++ (and then C#, I have plans to share this dll between a C++ and C# applications) using QT creator but when I try to use it I get SEGFAULT error.

Here's my files:

mydll.h

#ifndef MYDLL_H
#define MYDLL_H

#include "mydll_global.h"

class MYDLLSHARED_EXPORT MyDll
{

public:
    MyDll();
    int getAnswer();
};


MYDLLSHARED_EXPORT int getNumber();

#endif // MYDLL_H

mydll_global.h

#ifndef MYDLL_GLOBAL_H
#define MYDLL_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(MYDLL_LIBRARY)
#  define MYDLLSHARED_EXPORT Q_DECL_EXPORT
#else
#  define MYDLLSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // MYDLL_GLOBAL_H

mydll.cpp

#include "mydll.h"


MyDll::MyDll()
{
}

int MyDll::getAnswer()
{
    return 42;
}

int getNumber()
{
    return 10;
}

So I build it and created mydll.dll: then I went to other C++ project wheere I want to use this dll and put in the .pro file:

LIBS += "C:\path\to\mydll.h"

and in the main.cpp

#include "mydll.h"

and when I use function from dll like this:

 qDebug() << getNumber();

I get a SEGFAULT error.

I thought that the header to provide the compiler type information and the dll to compiler to provide the function body was all I needed but as I'm getting a SEGFAULT I'm acessing NULL or someone else memory or so (I can't see the value on debug).

What am I missing?

Alexander V

First off, to link the DLL you need the link .lib file for that DLL. That file has all the binary manifest for linking.

Second, project file LIBS clause specify the list of .lib files to link with. Some of them may represent dynamic libraries (.dll).

See the example: Linking to Shared Library in Qt

Even better article covering both creation of DLL with Qt and using DLL in your Qt project: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Qt Application Calling Dll from Fortran

From Dev

Error calling a function from unmanaged dll

From Dev

Calling any function from dll throws error

From Dev

Calling function from dll with pointer not working

From Dev

Calling function from Fortran DLL with Char as parameter

From Dev

Calling a Fortran function from Qt C++

From Dev

Calling Java function from Qt C++

From Dev

Calling a function from a DLL which is developed in C++ from C

From Dev

Invalid allocation size when calling a function from dll

From Dev

Calling the function using pointer parameter of Dll from .NET

From Dev

Error while calling C DLL function from Python

From Dev

Crash when calling c++ dll function from c#

From Dev

in C# calling from dll a C function with both wchar and char

From Dev

Calling a C++ function from Qt (slot does not work)

From Dev

Calling DLL from another namespace

From Dev

Calling a function from a function

From Dev

Calling function in C dll from C# which returns somekind of pointer to function pointer

From Dev

Calling Qt slot from JavaScript

From Dev

Calling a widget from Qt Designer

From Dev

Ctypes WindowsError: exception: access violation writing 0x0000000000000000 while calling a DLL function from another dll file

From Dev

Calling my own DLL from Azure Function, supported .NET Framework versions

From Dev

calling a dll function that takes a pointer to a handle (win32) from python

From Dev

Calling function in C# DLL from Delphi has parameter stuck on single value

From Dev

Python ctypes TypeError while calling a DLL function

From Dev

Error while calling function through C DLL

From Dev

Calling C++ DLL function with pointer

From Dev

Calling function of mpusbapi dll file in python

From Dev

Calling a function from data()

From Dev

Calling a Function from SQL

Related Related

  1. 1

    Qt Application Calling Dll from Fortran

  2. 2

    Error calling a function from unmanaged dll

  3. 3

    Calling any function from dll throws error

  4. 4

    Calling function from dll with pointer not working

  5. 5

    Calling function from Fortran DLL with Char as parameter

  6. 6

    Calling a Fortran function from Qt C++

  7. 7

    Calling Java function from Qt C++

  8. 8

    Calling a function from a DLL which is developed in C++ from C

  9. 9

    Invalid allocation size when calling a function from dll

  10. 10

    Calling the function using pointer parameter of Dll from .NET

  11. 11

    Error while calling C DLL function from Python

  12. 12

    Crash when calling c++ dll function from c#

  13. 13

    in C# calling from dll a C function with both wchar and char

  14. 14

    Calling a C++ function from Qt (slot does not work)

  15. 15

    Calling DLL from another namespace

  16. 16

    Calling a function from a function

  17. 17

    Calling function in C dll from C# which returns somekind of pointer to function pointer

  18. 18

    Calling Qt slot from JavaScript

  19. 19

    Calling a widget from Qt Designer

  20. 20

    Ctypes WindowsError: exception: access violation writing 0x0000000000000000 while calling a DLL function from another dll file

  21. 21

    Calling my own DLL from Azure Function, supported .NET Framework versions

  22. 22

    calling a dll function that takes a pointer to a handle (win32) from python

  23. 23

    Calling function in C# DLL from Delphi has parameter stuck on single value

  24. 24

    Python ctypes TypeError while calling a DLL function

  25. 25

    Error while calling function through C DLL

  26. 26

    Calling C++ DLL function with pointer

  27. 27

    Calling function of mpusbapi dll file in python

  28. 28

    Calling a function from data()

  29. 29

    Calling a Function from SQL

HotTag

Archive