How to link to qaxserver.def entities properly - qt

all
I'm trying to create ActiveX server with Qt5.2.0.
According to some pieces of information I have, to create a simple ActiveX server (which exports one object) it's enough to:
have such .pro file
TEMPLATE = lib
CONFIG += dll axserver
TARGET = simpleServer
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core
RC_FILE = qaxserver.rc
DEF_FILE = qaxserver.def
HEADERS += myserver.h
SOURCES += main.cpp
SOURCES += myserver.cpp
have such main.cpp file
#include "ActiveQt/QAxFactory"
#include "myserver.h"
QAXFACTORY_DEFAULT( MyServer, 5 id's )
the class should inherit QWidget and QAxBindable
there should be file qaxserver.rc. in my case it's content is 1 TYPELIB "simpleServer.pro"
there should be fie qaxserver.def with default contents:
; mfc_test.def : Declares the module parameters.
EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
DumpIDL PRIVATE
the problem is that these 5 names are undefined for Visual Studio's linker.
How to solve the problem?
the error is:
error LNK2001: unresolved external symbol DllCanUnloadNow

need to add QT += axserver in .pro file

Related

Qt Plugin Loading fails (specified module could not be found)

For some reason I am unable to load my plugins anymore, although it has worked previously. I have a plugin loader code in my MainWindow, which is supposed to load every .dll found in a specific folder. The MainWindow Code contains the following:
Interface
#ifndef PLUGININTERFACE_H
#define PLUGININTERFACE_H
#include <QtPlugin>
// forward declarations
class MainWindow;
struct P3DData;
class PluginInterface
{
public:
virtual bool createPublisher(MainWindow*, P3DData*) = 0;
};
#define PLUGIN_INTERFACE_iid "PluginInterface"
Q_DECLARE_INTERFACE(PluginInterface, PLUGIN_INTERFACE_iid)
#endif // PLUGININTERFACE_H
loadPlugins()
bool MainWindow::loadPlugins()
{
QDir pluginsDir(qApp->applicationDirPath());
pluginsDir.cd("plugins");
const auto entryList = pluginsDir.entryList(QDir::Files);
for(const QString &fileName : entryList)
{
QString dllPath = pluginsDir.absoluteFilePath(fileName);
QPluginLoader* loader = new QPluginLoader(dllPath);
loaderList.push_back(loader);
QObject *plugin = loader->instance();
if (plugin)
{
pluginList.push_back(qobject_cast<PluginInterface *>(plugin));
pluginList.last()->createPublisher(this, simDataPtr);
pluginCount++;
continue;
}
else
{
qDebug() << "[PluginLoader] '" + fileName + "': " + loader->errorString();
delete loaderList.takeLast();
}
}
}
Besides my MainWindow, there is another subdir in my project, which is the plugin "Position". The plugin is deployed into the correct "plugins" folder, which the loadPlugin() method from the MainWindow iterates through. The plugin uses following code to implement the interface:
#include <QObject>
#include "MainWindow.h"
class PositionPublisher : public QObject, PluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "PluginInterface")
Q_INTERFACES(PluginInterface)
public:
PositionPublisher();
~PositionPublisher();
bool createPublisher(MainWindow* _window, P3DData* _simDataPtr) override;
//...
};
When trying to run loadPlugins() now, it checks the correct Position.dll file but the "if(plugin)" part returns false and loader->errorString() is executed giving the following error:
[PluginLoader] 'Position.dll': Cannot load library
F:\DEV\build\simNET\bin\plugins\Position.dll: Cannot find the
specified module.
I have already checked and tried the following:
the Plugins folder actually contains the Position.dll file
both projects (MainWindow and Plugin) are built in release mode
the dependencies of the plugin (two libs) exist and the specified path in the pro file is correct
.pro file of plugin:
QT += widgets
TEMPLATE = lib
CONFIG += c++11
CONFIG += plugin
CONFIG += release
SOURCES += \
Position.cpp \
PositionPubSubTypes.cpp \
PositionPublisher.cpp
HEADERS += \
Position.h \
PositionPubSubTypes.h \
PositionPublisher.h
DISTFILES += \
Position.idl
INCLUDEPATH += ../../application
TARGET = $$qtLibraryTarget(Position)
DESTDIR = ../../bin/plugins
INCLUDEPATH += "F:/DEV/prog/FastRTPSv1.5/include"
DEPENDPATH += "F:/DEV/prog/FastRTPSv1.5/include"
LIBS += -L"F:/DEV/prog/FastRTPSv1.5/lib/x64Win64VS2015" -lfastrtps-1.5
PRE_TARGETDEPS += F:/DEV/prog/FastRTPSv1.5/lib/x64Win64VS2015/fastrtps-1.5.lib
INCLUDEPATH += 'F:/Programme/Prepar3D v4/SDK/inc/SimConnect'
DEPENDPATH += 'F:/Programme/Prepar3D v4/SDK/inc/SimConnect'
LIBS += -L'F:/Programme/Prepar3D v4/SDK/lib/SimConnect' -lSimConnect
PRE_TARGETDEPS += 'F:/Programme/Prepar3D v4/SDK/lib/SimConnect/SimConnect.lib'
Does anyone have an idea why it does not load the plugin??
Qt plugin loader is trying to tell you that a Qt module used in your plugin doesn't exist so first you need to check which Qt modules your plugin depends on then,
If you're trying to run the application from Qt Creator itself, and it gives you this error, then maybe the DLL file got deleted for some reason or you're trying to use the plugin with a Qt version that doesn't have its needed modules. (for example, Qt6 doesn't contain the QtSerialPort module but Qt5 did (at the time of writing this)).
If you're trying to run the application directly outside Qt Creator then you need to copy the required module's dll file into your applications root directory.

QLibrary does not load

I'm trying to write a simple example of loading a dll file, and the load fails.
I'm using qt 5.1.1 qt creator 3.0.1.
my compiler is: Microsoft Visual C++ Compiler 11.0 (amd64)
the pro file:
QT += core
TARGET = rrrr
SOURCES += main.cpp
the main file is:
#include <QLibrary>
int main()
{
bool is;
QLibrary lib("C:\\A.dll");
is = lib.load();
is = lib.isLoaded();
return 0;
}
The A.dll file of-course exists inside C.
I get the value false for the variable "is" while debbuging.

Qt Multimedia - how to force read tags from media file

It seems to be QMediaPlayer doesn't read tags of playlist files without of executing method play() of current track. Is there a way to force read tags from QMediaPlayer playlist without of playing it?
Sorry if this if a noob question, but I spent a lot of time for searches.
Thanks
Don't waste your time to use QMediaPlayer to read tags (this solution works good, but difficult for many files in list), simply use TagLib or another open-source library.
For example, 3 simple steps to use TagLib in Qt:
1.Compile taglib from source:
$ pwd
/home/user/taglib-1.9.1
$ cmake .
$ make
It's enough to deploy working instance of tag library. Really :)
2.Include headers and library in your project, simply add this or your custom path to project file:
unix:!macx: LIBS += -L$$PWD/3rdparty/taglib-1.9.1/taglib/ -ltag
INCLUDEPATH += $$PWD/3rdparty/taglib-1.9.1/taglib/Headers
DEPENDPATH += $$PWD/3rdparty/taglib-1.9.1/taglib/Headers
3.Use it, very simple function to get media tags from files, in this example artist and title of track:
#include <fileref.h>
#include <tag.h>
QString gettags(QString mediafile){
QString string;
TagLib::FileRef file(mediafile.toUtf8());
TagLib::String artist_string = file.tag()->artist();
TagLib::String title_string = file.tag()->title();
QString artist = QString::fromStdWString(artist_string.toWString());
QString title = QString::fromStdWString(title_string.toWString());
string = artist + " - " + title;
return string;
}
For the current QT/OSX, use this project file snippet (change paths for your system)
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11
LIBS += -L/Users/sir/prg.qt/TuneMerge/taglib-1.11.1/taglib/ -ltag -lz
INCLUDEPATH += /Users/sir/prg.qt/TuneMerge/taglib-1.11.1/
INCLUDEPATH += /Users/sir/prg.qt/TuneMerge/taglib-1.11.1/taglib/
INCLUDEPATH += /Users/sir/prg.qt/TuneMerge/taglib-1.11.1/taglib/toolkit/
DEPENDPATH += /Users/sir/prg.qt/TuneMerge/taglib-1.11.1/taglib

OpenCV 2.4.6 with QT 5.1.0 Errors

I am trying to get OpenCv2.4.6 to work with QT5.1.0
I've followed this Guide so far Qt creator 5.0.1 with OpenCv 2.3.4 on windows
Unfortunatly after finishing trying out the sample Application(Display an Image using OpenCv in the QtCreator I get these Errors:
[Project-Path]\main.o:-1: In function `main':
[Project-Path]\main.cpp:8: error: undefined reference to `cv::imread(std::string const&, int)'
[Project-Path]\main.cpp:9: error: undefined reference to `cv::namedWindow(std::string const&, int)'
[Project-Path]\main.cpp:10: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
[Project-Path]\main.cpp:10: error: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
[Project-Path]\main.cpp:11: error: undefined reference to `cv::waitKey(int)'
[Project Build Path Desktop Debug]\debug\main.o:-1: In function `ZN2cv3MatD1Ev':
[OpenCV/Install/include]\opencv2\core\mat.hpp:278: error: undefined reference to `cv::fastFree(void*)'
[Project Build Path Desktop Debug]\debug\main.o:-1: In function `ZN2cv3Mat7releaseEv':
[OpenCV/Install/include]\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()'
collect2.exe:-1: error: error: ld returned 1 exit status
the "[]" Paths are my formatting and supposed to help keep track .
main.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
// read an image
Mat image = imread("img.jpg");
namedWindow("My Image");
imshow("My Image", image);
waitKey(5000);
return 1;
}
myFirstOpenCVProject.pro
QT += core
QT -= gui
TARGET = myFirstOpenCVProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/qt/OpenCV246_bin/install/include
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_core246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_highgui246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_imgproc246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_features2d246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_calib3d246.dll
Can you help me resolve this?
I can't find any solutions that apply to my case ...
-L is to add directories to the search path. The actual libs are added via -l. The correct line would be:
LIBS += -LC:/qt/OpenCV246_bin/install/lib -llopencv_core246 -llopencv_highgui246 ...
I think you are missing the static libs of opencv:
opencv_core246.lib
opencv_highgui246.lib
opencv_video246.lib
opencv_ml26d.lib
opencv_legacy246.lib
opencv_imgproc246.lib
opencv_whatever.lib
Don t know the pro commands very well. Maybe something like:
LIBS += -Lc:/blabla/opencv_imgproc246.lib

Linking Qt DLL to Qt App - unresolved references

I've just installed Qt 4.7.4 and trying to make a simple Qt App that uses Qt DLL. I added export/import in a class in DLL through ifdef as usual but when compiling App I het unresolved references. I also set that App depends on the DLL.
Here are the main files:
Lib.pro
QT -= gui
TARGET = Lib
TEMPLATE = lib
DEFINES += LIB_LIBRARY
SOURCES += lib.cpp
HEADERS += lib.h\
Lib_global.h
symbian {
MMP_RULES += EXPORTUNFROZEN
TARGET.UID3 = 0xE10C4E25
TARGET.CAPABILITY =
TARGET.EPOCALLOWDLLDATA = 1
addFiles.sources = Lib.dll
addFiles.path = !:/sys/bin
DEPLOYMENT += addFiles
}
unix:!symbian {
maemo5 {
target.path = /opt/usr/lib
} else {
target.path = /usr/lib
}
INSTALLS += target
}
App.pro
QT += core gui
TARGET = App
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
lib.h
#ifndef LIB_H
#define LIB_H
#include "Lib_global.h"
#include <QString>
class LIBSHARED_EXPORT Lib {
public:
Lib();
~Lib();
QString Hello(QString a);
};
#endif // LIB_H
Lib_global.h
#ifndef LIB_GLOBAL_H
#define LIB_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(LIB_LIBRARY)
# define LIBSHARED_EXPORT Q_DECL_EXPORT
#else
# define LIBSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // LIB_GLOBAL_H
What's wrong with this code? Why is it unresolved reference?
In App I just include "../Lib/lib.h" and try to use the class.
What looks to be missing is the link between your application and your dynamic library.
I usually do something like this for my desktop (linux) apps:
INCLUDEPATH += ./include
LIBS += -L./lib -lLib
Where:
INCLUDEPATH defines the path to where your shared library .h files are located.
LIBS defines the path to where your built library is.
You can find the relevant documentation here: QMake - Declaring Other Libraries
Updated:
I was able to build the project (Linux Qt v4.7.4) and link to the library using the code you posted. I will try to clarify as my response may not be entirely clear.
The INCLUDEPATH and LIBS variables must be added to the App.pro file.
For the linker to properly find the library the paths must be adjusted to the paths you are using for your project:
LIBS += -L PATH -l LIBNAME
Supposing your folder structure is similar to the following:
Project
|_ Lib (your sharded library project files)
|_ App (your application project files)
You would adjust the variables like so:
INCLUDEPATH += ../Lib
LIBS += -L../Lib -lLib
Note that you link differently depending on your platform, you can do something like this to cover Windows and Linux:
unix {
INCLUDEPATH += ../Lib
LIBS += -L../Lib -lLib
}
win32 {
INCLUDEPATH += ../Lib
LIBS += ../Lib.lib
}

Resources