Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print hook not working #61

Open
diniamo opened this issue Oct 28, 2021 · 48 comments
Open

Print hook not working #61

diniamo opened this issue Oct 28, 2021 · 48 comments
Labels

Comments

@diniamo
Copy link

diniamo commented Oct 28, 2021

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?

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

How do you connect to the signal?

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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 Shatur added the bug label Oct 28, 2021
@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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
Copy link
Author

diniamo commented Oct 28, 2021

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

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

That's impossible.

image

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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})

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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)

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Oh I can do that?
huh lemme try

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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

Clearly CMake can't find Qt5 for you.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

That's because I use Qt6 lol.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

Then you maybe want to set QT_MAJOR to 6?

set(QT_MAJOR 5 CACHE STRING "Qt major version to use")

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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?

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

nop, same thing

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

Are you aware that you should put it before FetchContent_MakeAvailable?

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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
Copy link
Author

diniamo commented Oct 28, 2021

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

doesn't seem to work either

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

Have you tried clearing the cache?

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

No, I mean CMakeCache.txt.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Nope, doesn't seem to do anything.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

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.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

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.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Well tell me what I should tell you then?

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

Try to provide a concrete steps.
You need to overwrite QT_MAJOR if you going to use FetchContent.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

set(QT_MAJOR 6)
set(QT_MAJOR 6 CACHE STRING "Use Qt6")
#find_library(QHOTKEY_LIBRARY NAMES qhotkey1 QHotkey1 HINTS "${CMAKE_PREFIX}/lib")
include(FetchContent)
option(QHOTKEY_INSTALL OFF)
FetchContent_Declare(QHotkey
    GIT_REPOSITORY https://github.com/Skycoder42/QHotkey
    GIT_TAG 1.4.2
)
FetchContent_MakeAvailable(QHotkey)

This is what I was trying. The 2 set function calls weren't used at the same time of course.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

Thanks! Could you try to manually edit QHotkey's CMakeLists.txt (located under _deps/qhotkey-src in your build folder)? I would try to remove CACHE. Then you need to remove CMakeCache.txt from your build folder.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Which of the set calls should I use though?

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

I would go with set(QT_MAJOR 6). And try to remove CACHE parameter from the set from QHotkey.
We will update the repo if it fixes your issue.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

I think i found the issue and fixed it. Try this one:

include(FetchContent)

set(QT_DEFAULT_MAJOR_VERSION 6)
option(QHOTKEY_INSTALL OFF)
FetchContent_Declare(QHotkey
    GIT_REPOSITORY https://github.com/Skycoder42/QHotkey
    GIT_TAG 1.5.0
)
FetchContent_MakeAvailable(QHotkey)

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Hm okay that compiles, the warning doesn't appear anymore.
But I still don't get the print message.

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

Perhaps you have other applications running that intercept this hotkey?

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Okay so changing it to another key, or example it works

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

which you can clearly see from me leaving out the Fs in that message lol

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Perhaps you have other applications running that intercept this hotkey?

I had one but I closed that.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

I went through all the trouble of setting this up, and the one key I need doesn't work.. :b

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Guess I'll just implement this with a different hotkey until we find a solution...

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

I checked it myself, I can reproduce it on Windows. But it works on Linux.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

So does that mean it's not gonna get fixed?

@Shatur
Copy link
Collaborator

Shatur commented Oct 28, 2021

I am not familiar with Windows API and cannot tell what the problem might be. But pull requests are welcome.

@diniamo
Copy link
Author

diniamo commented Oct 28, 2021

Yeah well, I might try to look into it, I don't feel like I'm smart enough for windows api tho lol

Anyways, thank you for the help, let's keep this issue open then.

@diniamo
Copy link
Author

diniamo commented Oct 29, 2021

Okay so, I found out that it might be qt's fault or something, because I can't even enter print screen in a QKeySequenceEdit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants