QHotkey icon indicating copy to clipboard operation
QHotkey copied to clipboard

Print hook not working

Open diniamo opened this issue 4 years ago • 48 comments

This is the code I use for creating the hotkey:

d_hotkey = new QHotkey(Qt::Key_Print, Qt::NoModifier, true, this);
qDebug() << "Is registered:" << d_hotkey->isRegistered();

It is printing true, but however many ways I try to connect the signal to a slot, it just doesn't work. It either prints:

qt.core.qobject.connect: QObject::connect: signal not found in QHotkey

or straight up doesn't do anything.

I'm on a Windows system.

Any ideas why this could be?

diniamo avatar Oct 28 '21 09:10 diniamo

How do you connect to the signal?

Shatur avatar Oct 28 '21 11:10 Shatur

As I said, I've tried every way I know.

QObject::connect(d_hotkey, SIGNAL(activated()), this, SLOT(printCaught()));
QObject::connect(d_hotkey, SIGNAL(activated(QPrivateSignal)), this, SLOT(printCaught(QPrivateSignal)));
QObject::connect(d_hotkey, &QHotkey::activated, this, [&](){
...
});
QObject::connect(d_hotkey &QHotkey::activated, this, &TrayHandler::printCaught);

TrayHandler is the type of *this.

I think there were a few more I tried but I don't remember.

diniamo avatar Oct 28 '21 11:10 diniamo

qt.core.qobject.connect: QObject::connect: signal not found in QHotkey

This message just says that you connected it wrong. Probably from one of the attempts.

But last two are 100% good. So the shortcut is not emitted for some reason.

Shatur avatar Oct 28 '21 11:10 Shatur

Hm.. I get the warning on the lambda one so that's interesting. I also thought it would be good since that's in the example in the readme. Same with the last one.

diniamo avatar Oct 28 '21 11:10 diniamo

Also, just to clarify, Qt::Key_Print is print screen right?

diniamo avatar Oct 28 '21 11:10 diniamo

Hm.. I get the warning on the lambda one so that's interesting.

That's impossible.

Also, just to clarify, Qt::Key_Print is print screen right?

Right.

Shatur avatar Oct 28 '21 12:10 Shatur

That's impossible.

image

diniamo avatar Oct 28 '21 12:10 diniamo

I can't reproduce it, the example from the README works jut fine for me without this message. It could be cause only by the old connect syntax. Something wrong with your code.

Shatur avatar Oct 28 '21 13:10 Shatur

Could it be with the way I add the dependency? Because it feels kinda wrong. That's the only thing I can think of at this point, since the HotkeyTest example works.

Cmake code:

find_library(QHOTKEY_LIBRARY NAMES qhotkey1 QHotkey1 HINTS "${CMAKE_PREFIX/lib}")
target_link_libraries(QuickScreenshot PRIVATE ${QHOTKEY_LIBRARY})

diniamo avatar Oct 28 '21 13:10 diniamo

Because it feels kinda wrong. That's the only thing I can think of at this point, since the HotkeyTest example works.

You probably using it wrong. Try this one:

cmake_minimum_required(VERSION 3.16)

project(project LANGUAGES CXX)

include(FetchContent)

option(QHOTKEY_INSTALL OFF)
FetchContent_Declare(QHotkey
    GIT_REPOSITORY https://github.com/Skycoder42/QHotkey
    GIT_TAG 1.4.2
)
FetchContent_MakeAvailable(QHotkey)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE QHotkey::QHotkey)

Shatur avatar Oct 28 '21 13:10 Shatur

Oh I can do that? huh lemme try

diniamo avatar Oct 28 '21 13:10 diniamo

It's trying to search for Qt5 for some reason.

  By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt5" with any of
  the following names:

    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
  to a directory containing one of the above files.  If "Qt5" provides a
  separate development package or SDK, be sure it has been installed.

diniamo avatar Oct 28 '21 13:10 diniamo

It's trying to search for Qt5 for some reason.

Clearly CMake can't find Qt5 for you.

Shatur avatar Oct 28 '21 13:10 Shatur

That's because I use Qt6 lol.

diniamo avatar Oct 28 '21 13:10 diniamo

Then you maybe want to set QT_MAJOR to 6?

https://github.com/Skycoder42/QHotkey/blob/1114df5081f2cda334531ac664c7434c13dccfe6/CMakeLists.txt#L11

Shatur avatar Oct 28 '21 13:10 Shatur

Erm... how do I do that though? Since that's in the github repo

diniamo avatar Oct 28 '21 13:10 diniamo

Erm... how do I do that though? Since that's in the github repo

How about to put set(QT_MAJOR 6) in your CMakeLists.txt before including QHotkey?

Shatur avatar Oct 28 '21 13:10 Shatur

nop, same thing

diniamo avatar Oct 28 '21 13:10 diniamo

Are you aware that you should put it before FetchContent_MakeAvailable?

Shatur avatar Oct 28 '21 13:10 Shatur

Or try this one: set(QT_MAJOR 6 CACHE STRING "Use Qt6")

Shatur avatar Oct 28 '21 13:10 Shatur

Are you aware that you should put it before FetchContent_MakeAvailable? Yes, and I did.

I'll try the other one in about an hour because I have to go.

diniamo avatar Oct 28 '21 13:10 diniamo

Or try this one: set(QT_MAJOR 6 CACHE STRING "Use Qt6")

doesn't seem to work either

diniamo avatar Oct 28 '21 15:10 diniamo

Have you tried clearing the cache?

Shatur avatar Oct 28 '21 15:10 Shatur

If by that you mean clean & build. I just did. Same thing.

diniamo avatar Oct 28 '21 16:10 diniamo

No, I mean CMakeCache.txt.

Shatur avatar Oct 28 '21 16:10 Shatur

Nope, doesn't seem to do anything.

diniamo avatar Oct 28 '21 16:10 diniamo

I don't have much information to understand what are you trying. But you need to find a way to override this variable.

Shatur avatar Oct 28 '21 16:10 Shatur

The default qt script uses the variable called QT_VERSION_MAJOR so it doesn't make sense why I need this one. And I'm trying what you told me but it doesn't seem to do a thing.

diniamo avatar Oct 28 '21 16:10 diniamo

The default qt script uses the variable called QT_VERSION_MAJOR so it doesn't make sense why I need this one.

Because this won't work with old Qt versions.

And I'm trying what you told me but it doesn't seem to do a thing.

I just guessing. You are not providing enough information for me to help you.

Shatur avatar Oct 28 '21 16:10 Shatur

Well tell me what I should tell you then?

diniamo avatar Oct 28 '21 16:10 diniamo