简体   繁体   中英

How to include libs into Qt project?

I'm trying to figure out how to use the winapi SetWindowSubclass

On a non-Qt project under MSVC I can use the API by including:

#include <commctrl.h>
#pragma comment(lib, "Comctl32.lib")

I have been trying for hours unsuccessfully to link this lib on my project. I have found these comctl32.lib on my machine: https://i.imgur.com/D5uOCVb.png

I tried adding into .pro :

LIBS += -comctl32

LIBS += -comctl32.lib => error: unrecognized command-line option '-comctl32'

LIBS += comctl32

LIBS += comctl32.lib => error: cannot find comctl32: No such file or directory

I copied the one from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\arm64 and past it on a new folder under C:\Qt\Libs

LIBS += C:\Qt\Libs => error: cannot find C:\Qt\Libs: Permission denied

LIBS += -L"C:\Qt\Libs" => this didn't throw any of the errors from above, but now I have these compiler error:

在此处输入图像描述

.pro

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17

LIBS += -L"C:\Qt\Libs"
#win32:QMAKE_FLAGS += -L"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\arm64"
#win32:LIBS += cm-comctl32.lib

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.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 += \
    rcdata.qrc

.h

#include <commctrl.h>
#pragma comment(lib, "Comctl32.lib") // <- warning: Unkown pragma ignored

.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    SetWindowSubclass((HWND)ui->tabWidget->find(0), ButtonProc, 0, (DWORD_PTR)&ui);
    DWORD err = GetLastError();
}

Using Qt Creator 8.0.1

Qt 6.3.1, compiler MinGW 64-bit

It should be LIBS += -lcomctl32 for your compiler instead of the several other options you tried. This related question has additional detail: Adding external library into Qt Creator project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM