Error using GetModuleFileNameExA function in Qt - qt

#include <iostream>
#include <windows.h>
#include <psapi.h>
#include <tlhelp32.h>
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, 7632);
wchar_t lpFilename[1024];
GetModuleFileNameExW(hProcess, NULL, lpFilename, sizeof(lpFilename));
qDebug() << QString::fromWCharArray(lpFilename);
CloseHandle(hProcess);
The above code runs normally in vs2019, but when I use it wrong in qt, this error occurs:
error: undefined reference to `GetModuleFileNameExA'
error: ld returned 1 exit status

Need to load Psapi.lib
Add in the <project name>.pro file
...
LIBS += \
-lPsapi
...

Related

Trying to get 'Style' list for a GtkWidget

I'm trying hard to get a list of style properties for a GtkWidget (GtkButton). This is my code so far:
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
// Declare variables.
GtkWidget *btn = gtk_button_new();
guint *count = {0};
GParamSpec **list = NULL;
// Initialize gtk.
gtk_init(&argc, &argv);
// Get style properties.
list = gtk_widget_class_list_style_properties(GTK_WIDGET_CLASS(btn), count);
// Exit cleanly.
exit(EXIT_SUCCESS);
}
I get a clean compile with:
gcc -o gtk_test gtk_test.c `pkg-config --cflags --libs gtk+-3.0`
But I get the following errors when run:
(process:72182): Gtk-CRITICAL **: 10:42:23.167: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
(process:72182): Gtk-CRITICAL **: 10:42:23.167: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
(process:72182): Gtk-CRITICAL **: 10:42:23.167: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
Segmentation fault
I don't think I'm doing it right, but I can't find any examples that use gtk_widget_class_list_style_properties that I understand. They ones I do find use klass and the first argument. But I can never find where klass is declared or even what it is.
Can someone please help point me in the right direction? I went to the gtk website and did a search on GTK_WIDGET_CLASS and it came back with nothing! Very frustrating to say the least.
What am I supposed to use for the GTK_WIDGET_CLASS argument that will return the style properties for a GtkButton?
I tried out your sample code. Actually, it looks like you just have the incorrect macro. Instead of:
GTK_WIDGET_CLASS(btn)
try:
GTK_WIDGET_GET_CLASS(btn)
I tried that and then received no critical messages.
Regards.

QT + OpenCV undefiend reference to cv::stereoBM::create(int,int)

I need your help for a problem in OpenCV cv::StereoBM because I got an error when I tried bo compile the code below:
std::string myImgLeftString = myImgLeft.toUtf8().constData();
std::string myImgRightString = myImgRight.toUtf8().constData();
cv::Mat img1 = cv::imread(myImgLeftString,CV_LOAD_IMAGE_COLOR);
cv::Mat img2 = cv::imread(myImgRightString,CV_LOAD_IMAGE_COLOR);
cv::Mat img3;
cv::Mat img1grey, img2grey;
cv::cvtColor(img1,img1grey,CV_BGR2GRAY);
cv::cvtColor(img2,img2grey,CV_BGR2GRAY);
cv::Ptr<cv::StereoBM> match = cv::StereoBM::create(0,21);
match->compute(img1grey,img2grey,img3);
It gives me : undefiend reference to cv::StereoBM::create(int,int)
But I already include all the headers necessary and not necessary
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/imgproc.hpp>
#include <stdio.h>
#include <iostream>
#include <opencv2/core/affine.hpp>
#include "opencv2/core/hal/intrin.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/ximgproc.hpp"
And I've added two lignes of code in my .pro file
LIBS += -L ./opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs
INCLUDEPATH += -I /opt/local/stow/opencv-3.4.3
I don't know what is wrong, please kindly help, thanks.
cv::StereoBM is in calib3d module of OpenCV, so you need to link to the lib file of that module, to do that add -lopencv_calib3d to the LIBS in your .pro file:
LIBS += -L ./opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_calib3d
Don't forget to run qmake after you modify your .pro file.

Ploting an image with 'imshow' of opencv in webots

hi I am using opencv in webots and I want to plot an image . This is the controller:
#include <webots/Robot.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace webots;
using namespace cv;
int main(int argc, char **argv){
Robot *robot = new Robot();
int timeStep = (int) robot->getBasicTimeStep();
while (robot->step(timeStep) != -1) {
Mat a1 = imread("/home/alireza/Desktop/1.jpg");
cv::imshow("test",a1);
};
delete robot;
return 0;
}
and this is the makefile:
OPENCV = `pkg-config opencv --cflags --libs`
LIBRARIES = $(OPENCV)
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
RESOURCES_PATH = $(WEBOTS_HOME)/projects/robots/robotis
CXX_SOURCES = $(wildcard *.cpp)
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
I make it successfully but when I want to run it I face a runtime error about Qt :
[co] qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
[co] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
I really need help.

Programm crashes using Taglib

I am trying to use Taglib with Qt5.7. But my programm crashes:
The GDB process terminated unexpectedly (exit code 0).
Cannot continue debugged process: The program is not being run.
During startup program exited with code 0xc0000135
There did not seem to be any error messages while building Taglib.
*.pro file
QT += core
QT -= gui
CONFIG += c++11
TARGET = untitled2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
TAGLIBDIR = $$quote(D:/D/Programmieren/Libraries/taglib)
INCLUDEPATH += $$quote( $${TAGLIBDIR}/include )
LIBS += -L$$quote($${TAGLIBDIR}/lib) -ltag
main.cpp
#include <QCoreApplication>
#include <taglib/tag.h>
#include <taglib/fileref.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TagLib::FileRef ref("D:/D/Media/Musik/Disturbed/The Sickness/Disturbed - Stupify.mp3");
return a.exec();
}
Edit:
I created Taglib-buildfiles using CMake-GUI and native MinGW-Installation since I did not manage to create them using Qt. My OS is Windows 10 x64 Education and I use Qt-Creator. I downloaded the latest Taglib-Release (1.11.1)
Why I cant create buildfiles using CMake:
First some *dll-files where missing, i coud solve that by just copying the ones from native MinGW-Installation to QT-MinGW.
Second I could not find any of the *exe-files desired by CMake so i could not change the path from native MinGW-Installation.
After rebuilding Taglib in debugmode I get this errors:
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib8FileNameC1EPKc'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE'
main.cpp:11: error: undefined reference to `_imp___ZNK6TagLib7FileRef3tagEv'
main.cpp:11: error: undefined reference to `_imp___ZNK6TagLib6String9toCStringEb'
main.cpp:11: error: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
main.cpp:11: error: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
collect2.exe:-1: error: error: ld returned 1 exit status
Solved it by using new version (5.8 instead of 5.7) of Qt.

Why does this Qt header file fail to get parsed by moc?

I created a new 'C++ library' project in Qt, which has the following header file:
#include "Test_global.h"
#include <QString>
#include <QTcpServer>
class TESTSHARED_EXPORT Test : QTcpServer
{
Q_OJECT
public:
Test();
~Test();
signals:
void NewMessage(QString);
};
(The implementation file is basically empty.)
When I try to build the object, I get errors:
Test.h:8: error: ISO C++ forbids declaration of ‘Q_OJECT’ with no type
Test.h:10: error: expected ‘;’ before ‘public’
Test.cpp:3: error: definition of implicitly-declared 'Test::Test()'
So it looks like moc isn't processing the file at all. What have I done wrong?
It should be Q_OBJECT, not Q_OJECT.

Resources