Accessing NI-VISA from Qt C++ 4.7 - qt

I am developing a Windows (7) application using Qt (4.7.0) to call some methods in a DLL (NI visa32.dll) to communicate with instruments through the GPIB port. The manufacturer's header file is also available (visa.h).
In the project file, I tried adding the path and library reference to the original places where the files are located at as:
INCLUDEPATH += "C:/Program Files/National Instruments/Shared/CVI/Include"
LIBS += "C:/Windows/System32/visa32.dll"
but, I get the compilation error:
collect2: ld returned 1 exit status
Following the instructions in Importing a DLL into Qt, I created a "visa.a" from the "visa32.dll", and copied them to a subfolder "visa/lib", and added the path and library to the project file:
INCLUDEPATH += visa/include
LIBS += -Lvisa/lib
LIBS += -lvisa.a
I tried also with -lvisa or -lvisa.dll, but in all the cases I get also another compilation error saying that the -lvisa, -lvisa.a or -lvisa.dll is not found. I edited the original header file "visa.h", and prefixed with Q_DECL_IMPORT every object in the file, and also made sure that the extern "C" statement be present.
I include the reference to the header file in the application as:
#include "visa.h"
and note that the compiler does recognize the referenced objects belonging to the visa.h file.
Any help to solve this compilation error will be greatly appreciated.
I also tried with Visual C++ (2010) following the instructions of DLL References in Visual C++. In this case, I do not get any compilation error, but linking errors. For example:
AgiE364X.obj: error LNK2019: unresolved external symbol
"extern "C" long __stdcall viClose(unsigned long)"
being viClose a called method in NI-VISA.
I would prefer to use Qt C++ instead of Visual C++, though.
Thanks in advance.

I'm not sure since I'm new to Qt myself but here are some guesses: I noticed you have a space in INCLUDEPATH string. Also, LIBS += -Lvisa/lib has a capitol L (is this correct?). I'm not saying this is your problem but perhaps worth a try. The last thing that comes to mind is that if you're using Qt Creator only partially type #include "visa.h" and see if auto complete can complete it for you. If it can, than prob the rest is OK. Trigger auto-complete with Ctrl+Space. I've noticed that when I mess up the paths auto-complete is a good gauge for this sort of thing.

There are two types of library of VISA provided by NI: the one is compiled by borland c++, the other is compiled by microsoft vc++.
As for Qt, you can use Qt which should be compiled by MSVC, to link the visa32.lib which is compiled by MSVC too. And it MUST link .lib instead of .dll, The MSVC library of VISA is in "C:\Program Files\IVI Foundation\VISA\WinNT\lib\msc" by default.
The include directory is C:\Program Files\IVI Foundation\VISA\WinNT\include by default.
In fact, the above information can be known from VISA example after you install the device driver.

Related

How to set up poppler library in Qt for embedded device?

The goal is to show pdf's on my target => imx6 board + display. My host's OS is Linux.
So far i'm having a program written in Qt 5.
It compiles fine and i'm able to see it on the display.
To show some pdfs i would like to use the poppler library.
The problem is that i'm not able to get this done. Properly ...
My steps so far:
I did the basic installation of poppler like it is described in the INSTALL file.
mkdir build
cd build
cmake ..
make
make install
then added
INCLUDEPATH += /home/user/poppler/include/poppler/qt5
LIBS += -L"/home/user/poppler/lib" -lpoppler-qt5
to my .pro file
and the #include <poppler-qt5.h> to my .cpp file.
And the result when running is this:
/home/user/poppler/lib/libpoppler-qt5.so:-1: error: file not recognized: File format not recognized
:-1: error: collect2: error: ld returned 1 exit status
Now i have just two ideas. First one is to cross-compile the poppler source code. (I tried this with a toolchain file but failed :'D)
Second idea is to put the library into Qt together with my project and compile it there - maybe that could work. I just don't know how. Help.
I'm also open for something else then poppler - i just want to show pdf's.
The problem, here, is you are somehow compiling Qt projects for ARM, using the corresponding toolchain and sysroot and ABI, and you can not just link to libraries you compiled for, say, x86_64, because they're just binary incompatible.
In the very lucky case you managed to configure creator for cross compilation, just make a creator project for the poppler library, using cmake, and configure the project with the same kit you use for the imx6 applications. Once you have it built for ARM, you can proper link it in your app, providing the full path to LIBS in the .pro file.
In case you're using Yocto, instead, just make a recipe for poppler. In case you're not, maybe you should.

dbus - undefined reference to

This topic is related with following link . Temporarily I solved problem with headers: I just modified all include paths. When I try to call some dbus function, for example dbus_error_init(&err); I get a linker error: undefined reference to 'dbus_error_init'. libdbus-1.so is placed in /usr/lib/x86_64-linux-gnu so I added to pro file (I use Qt Creator) following line:
LIBS += -L/usr/lib/x86_64-linux-gnu -llibdbus-1
but I get follwoing info: cannot find -llibdbus-1 How to fix that ?
Usually it's just -ldbus-1 or -ldbus. You can also try adding CONFIG += dbus in your .pro file to enable the Qt DBUS classes, which if I remember rightly detects the DBUS library as well, as long as Qt was built with support for it.

Warning while building project using Qt 5.1 on OSX

I am getting two warnings while trying to build Qt projects on Mac (using QtCreator).
warning: No .qmake.cache is present. This significantly slows down
qmake with this makespec. warning: Call 'cache()' in the top-level
project file to rectify this problem.
The warning instructs to call cache() in the top level project, but I don't find any documentation on how I should do that.
I see some bugs logged on qt
https://bugreports.qt.io/browse/QTBUG-31340
https://bugreports.qt.io/browse/QTBUG-30586
I know this is just a warning, but I am interested in fixing it. Is there any workaround to fix it?
The solution is to call cache() in your main .pro file.
Then run qmake (from the QtCreator build menu) and rebuild the project.
The warning should be gone.
Example .pro:
cache()
QT += ...
//the rest of the .pro file

Compiling InterBase support in Qt

I have followed the instructions on http://doc.qt.nokia.com/stable/sql-driver.html#qibase for compiling Interbase support into Qt, and made sure all of my libraries are in the right place. qmake runs successfully, but when I run nmake, I get a series of undefined reference errors in qsql_ibase.cpp. If I open up the .pro in Qt Creator and hover over one of the functions that is throwing the undefined reference errors and follow the symbol (F2), it takes me to the ibase.h file where it is declared. Is it throwing the undefined reference errors because there is no function definition? If that is the case, why isn't it giving me any errors about a missing library?
Output example:
Creating library file: debug\libqsqlibased4.a
debug/qsql_ibase.o: In function getIBaseError':
C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../../sql/drivers/ibase
/qsql_ibase.cpp:80: undefined reference toisc_sqlcode'
C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../../sql/drivers/ibase
/qsql_ibase.cpp:85: undefined reference to isc_interprete'
debug/qsql_ibase.o:C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../.
./sql/drivers/ibase/qsql_ibase.cpp:406: undefined reference toisc_dsql_free_st
atement'
debug/qsql_ibase.o:C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../.
./sql/drivers/ibase/qsql_ibase.cpp:421: undefined reference to isc_create_blob2
'
debug/qsql_ibase.o:C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../.
./sql/drivers/ibase/qsql_ibase.cpp:427: undefined reference toisc_put_segment'
This continues for many more errors, all undefined references.
That really sounds like the first issue mentioned under the "Troubleshooting" section of the page to which you link above:
You should always use client libraries that have been compiled with
the same compiler as you are using for your project. If you cannot get
a source distibution to compile the client libraries yourself, you
must make sure that the pre-compiled library is compatible with your
compiler, otherwise you will get a lot of "undefined symbols" errors.
Some compilers have tools to convert libraries, e.g. Borland ships the
tool COFF2OMF.EXE to convert libraries that have been generated with
Microsoft Visual C++.
Which compiler are you using to compile Qt, and where did you get the Interbase libraries? You also need to make sure those libraries can be found at link time. If you look at the output of your compiler, it should show you all the link directories in which it is searching (in addition to any globally defined, like PATH in Windows.) If the folder with your Interbase library is listed, it is probably that the compiler versions aren't matching.
Sorry for raising so old theme, but I found a solution and want to share with it. The problem is that macro ISC_EXPORT was not defined in Interbase's SDK due to conditional compilation defines. See details here - Howto build Interbase plugin for Qt by MinGW

using external libraries in Qt/Symbian

To get Facebook integration in our Nokia Symbian application we intend to use this library:
http://gitorious.org/qfacebookconnect
It is not otherwise working completely correctly, but it's a good start.
I have my project (.pro and .cpp files, using Qt Creator), which works fine in the emulator. I included this libqfacebook in the project in this way (in the .pro file):
LIBS += -LC:\projects\Pristop\Nokia\facebook_lib\libqfacebook-build-simulator\debug -lqfacebookconnect
INCLUDEPATH += C:\projects\Pristop\Nokia\facebook_lib\qfacebookconnect\inc
It works fine in the emulator. I use Qt Creator for everything, also to build libqfacebook. But if I want to test the application on a real phone, so to prepare a .sis file, I get this error:
:: error: No rule to make target `\NokiaQtSDK\Symbian\SDK\epoc32\release\armv5\LIB\qfacebookconnect.dso', needed by `\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\DogajaItak.exe'. Stop.
So I need to get a .dso file based on the source code of the qfacebookconnect library. For the emulator .lib and .pdb were enough. Obviously the difference is that .dso is arm while .lib & .pdb are x86.
If I try to configure qfacebookconnect to build for the phone, I get this error:
Makefile:232: error: PKG file does not exist, 'sis' and 'installer_sis' target are only supported for executables or projects with DEPLOYMENT statement. Stop.
It is correct that I do not want a .sis, all I want is a .dso.
If I go to Projects->Build Settings for Symbian Device for qfacebookconnect and I remove the build step "create SIS package" for qfacebookconnect, there is no error anymore, but I still don't believe it built a .dso for me.
So the question is how to configure Qt Creator or the .pro file to build me a .dso, or how to include external libraries in my .sis in another way?
I needed to freeze the library..
I found all the information there:
https://code.google.com/p/qfacebookconnect/issues/detail?id=13

Resources