Results 1 to 7 of 7

Thread: Creating DLL file in Qt and using it in Java

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Creating DLL file in Qt and using it in Java

    Hi everyone,

    I am creating a simple shared library which contains the following files:
    mylib.h and mylib.cpp

    the code for mylib.pro is:
    Qt Code:
    1. QT -= gui
    2.  
    3. TARGET = myLIB
    4. TEMPLATE = lib
    5. SOURCES += mylib.cpp
    6.  
    7. HEADERS += mylib.h
    To copy to clipboard, switch view to plain text mode 


    the code for mylib.h is:
    Qt Code:
    1. #ifndef MYLIB_H
    2. #define MYLIB_H
    3.  
    4. extern "C"{
    5. __declspec(dllexport) int __stdcall hello();
    6. }
    7.  
    8. #endif // MYLIB_H
    To copy to clipboard, switch view to plain text mode 


    the code for mylib.cpp is:
    Qt Code:
    1. #include "mylib.h"
    2.  
    3. __declspec(dllexport) int __stdcall hello()
    4. {
    5. return 56; [QUOTE]hello() is a simple function which returns 56[/QUOTE]
    6. }
    To copy to clipboard, switch view to plain text mode 


    After building the project, i am getting a myLIB.dll file in debug directory. I am able to use this DLL in a visual C# project by referencing to the DLL in C# code.
    But i am not able to use the hello() function of the DLL in java.


    So, can anyone please tell me the correct way of creating a DLL in Qt, which i can further use in Java?


    Thanks in advance,

    With regards,
    Satya Prakash.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Creating DLL file in Qt and using it in Java

    This question has nothing to do with Qt.

    You want to read about Java Native Interface (JNI). That should enable your Java code to talk to suitable code you write in C or C++.

  3. The following user says thank you to ChrisW67 for this useful post:

    sattu (7th May 2011)

  4. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Creating DLL file in Qt and using it in Java

    Hi Chris,

    Thanks for replying. Actually now the problem is solved. As you told, I can do it by either using JNI or JNA package. Now, I am looking forward to using a DLL and it's methods in Qt. I hope, examples are available to guide regarding the use of DLLs in Qt.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Creating DLL file in Qt and using it in Java

    Your question was about using C/C++ libraries from Java. Now you are saying you want it the other way around.
    In either case, this has little to do with Qt.

  6. #5
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Creating DLL file in Qt and using it in Java

    Quote Originally Posted by ChrisW67 View Post
    Your question was about using C/C++ libraries from Java. Now you are saying you want it the other way around.
    In either case, this has little to do with Qt.
    Sorry for being in such a rush. Actually the project is such that it has to be both way. Creating a DLL in qt and using it in Java is fine.

    Now, the concern is that I have got a C++ DLL containing some functions. I have to use that DLL(and it's methods) in my Qt program. So, currently my problem is this. So, can you provide me some links or examples which can guide regarding the usage of DLL in Qt (both by static and dynamic linking).

    Thanking in advance,

  7. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Creating DLL file in Qt and using it in Java

    Qt is C++, so you need to search for info on how to link to external libraries using your C++ compiler, for example if its gcc, then look here: Linking with external libraries

  8. The following user says thank you to stampede for this useful post:

    sattu (7th May 2011)

  9. #7
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Creating DLL file in Qt and using it in Java

    Ok stampede, I will see to it and reply if I have got any doubt.

Similar Threads

  1. Creating xml file from Xml Schema (xsd) file
    By pieczara in forum Newbie
    Replies: 1
    Last Post: 25th February 2011, 23:11
  2. creating Xml file using QT
    By rk0747 in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2010, 11:16
  3. [java] write and read from file a dictionary
    By mickey in forum General Programming
    Replies: 1
    Last Post: 15th December 2008, 17:54
  4. [java newbie] cast reading a file
    By mickey in forum General Programming
    Replies: 0
    Last Post: 4th October 2008, 19:01
  5. [Java] read and write a file
    By mickey in forum General Programming
    Replies: 3
    Last Post: 22nd June 2008, 10:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.