Using the iphlpapi library in QT - qt

I am trying to use the GetAdaptersAddresses function
In QT for this I tried to import the iphlpapi.h
This is my code:
#include <iphlpapi.h>
int check_mac(char * mac_vendor)
{
unsigned long alist_size = 0, ret;
ret = GetAdaptersAddresses(AF_UNSPEC,0,0,0,&alist_size);
}
I'm getting this error :
error: C3861: 'GetAdaptersAddresses': identifier not found
This is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ooTptro
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
LIBS += Advapi32.lib
#LIBS += IPHLPAPI.lib
win32:LIBS += -lIPHLPAPI
Does anyone know why QT does not recognize the function and the include even though I have added both the include and the .pro file?

Related

How to turn on OpenGL acceleration in QCustomPlot?

My Qt version is 5.12.2. I have added DEFINES += QCUSTOMPLOT_USE_OPENGL in my .pro file. My .pro file is shown below:
#-------------------------------------------------
#
# Project created by QtCreator 2019-04-05T21:23:52
#
#-------------------------------------------------
QT += core gui
QT += charts
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
TARGET = oscilloscope_msvc2015
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QCUSTOMPLOT_USE_OPENGL
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp \
fourier.cpp \
plotdata.cpp \
datathread.cpp \
axisthread.cpp \
qcustomplot.cpp
HEADERS += \
mainwindow.h \
fourier.h \
plotdata.h \
datathread.h \
axisthread.h \
qcustomplot.h
FORMS += \
mainwindow.ui \
fourier.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
res.qrc
but when I use setOpenGl(true) to turn on OpenGL, it keeps reporting error:
void QCustomPlot::setOpenGl(bool, int) QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)
So how to turn on OpenGL acceleration in QCustomPlot?
Try to run qmake and then rebuild.
I had this problem and after doing these, it was ok.

qmake does not copy files (INSTALLS)

I have a Qt console app with the following .pro file:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
DISTFILES += \
data.txt
data_files.path = $$OUT_PWD
data_files.files = data.txt
INSTALLS += \
data_files
As you can see from my .pro file there are two files in project folder: main.cpp and data.txt
I want to copy data.txt from my source folder to build output folder and I know there is INSTALLS for my problem.
What's wrong with my .pro?

Qt Windows 32 bit deployment issues

I'm trying to deploy QT to a 32 bit Windows but when I try to run the file on other computers (I tried on Windows 10) I get an error:
The application was unable to start correctly (0xc000007b)
To make the deploy I used this:
C:\Qt\5.9.1\ msvc2015\bin\windeployqt.exe -release -compiler-runtime my_program.exe
This is a picture of the output (partially) of dependency walker
It is important to note that I also use additional libraries (OpenSSL and Boost) in my software here is my PRO file:
#-------------------------------------------------
#
# Project created by QtCreator 2017-10-01T05:52:49
#
#-------------------------------------------------
QT += core gui multimedia multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MypROGRAM
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
HEADERS += \
mainwindow.h \
FORMS += \
mainwindow.ui
RESOURCES += \
my_icones.qrc
#openssl
win32 {
INCLUDEPATH += c:/OpenSSL-Win32/include
# for openssl - I added these 2 lines
LIBS += -LC:\OpenSSL-Win32\lib -llibeay32
}
RESOURCES += \
my_icones.qrc
# add boost support
INCLUDEPATH += C:/boost_1_65_1/
LIBS += "-LC:/boost_1_65_1/lib/"
# special libs
LIBS += Advapi32.lib
LIBS += User32.lib
LIBS += Mpr.lib
LIBS += Shlwapi.lib
LIBS += ntdll.lib
I would be very happy if any of you could help
Thanks.

Linking dll to c++ in qt for reading .mat files

I am using Qt Creator 2.4.1(Based on Qt 4.7.4) ..
Now I want to open the .mat file which I got from Matlab.
I am using the basic function matOpen
Initially, I knew the headers required. They are mat.h, matrix.h and tmw.h.
Now, before running the code, I need to link the libraries. The required libraries as far as I know are libmat.dll and libmw.dll . I added them to the .pro file as follows.
QT += core
QT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
HEADERS += \
mat.h \
matrix.h \
tmwtypes.h
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop- Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmat.dll"
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmx.dll"
Still I get error as : undefined reference to matOpen.. m sure the problem is with the linking.. But I dunno how to solve it. and the compiler Qt is using is MinGw .
You are specifying library path only, not the libraries itself. Try
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug"
LIBS += -llibmx
LIBS += -llibmat

Run time error for a missing DLL which exists

I am writing a tool with Qt Creator which builds but immediately crashes with the message:
"The program can't start because pthreadVC2.dll is missing from your
computer. Try reinstalling the program to fix this problem".
Of course, the "pthreadVC2.dll" library is not missing (and is not corrupted, since it works with other projects), and it is located in the path specified in the Qt pro file:
# DeltaPlots.pro
TARGET = DeltaPlots
QT += core gui
CONFIG += console
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
win32 {
INCLUDEPATH += S:\\3rdparty\\DFS.Infrastructure.ThreadingW \
S:\\3rdparty\\DFS.Infrastructure.File \
"C:\\path\\to\\boost\\boost_1_51_0"
win32-g++:LIBS += -L"S:\\lib\\" -lMyLib
win32-g++:LIBS += -L"S:\\3rdparty\\DFS.Infrastructure.File\\" -lDFS.Infrastructure.FileSystem
win32-g++:LIBS += -L"S:\\3rdparty\\DFS.Infrastructure.ThreadingW\\" -lDFS.Infrastructure.Threading -lpthreadVC2
}
SOURCES += MainWindow.cpp \
entrypoint.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
OTHER_FILES += ProjectList.txt \
ImageList.txt
Platform:
Windows 7
MinGW
Qt 4.8.3
Qt Creator 2.6.0
[Edit: This answer refers to the original question]
Usually you would add
LIBS += -LS:/3rdparty/DFS.Infrastructure.ThreadingW \
-lpthreadVC2
This adds your library's folder as a library search path (Note the capital -L) and pthreadVC2.lib as a library to link against (lower case -l).
You do not need to add the .dll to the LIBS path, as the .dll is loaded at runtime.
But: This approach only works when the .lib is in the same folder as the .dll. I'm a bit surprised you have yours in different locations.
Maybe adding
LIBS += -LS:/3rdparty
would work, but I'm not sure about that.
In any event, you need to deploy the .dll with your .exe for releases.

Resources