Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Add log to Qt source code



  • I have a embedded device,but the keyboard can't be used.So I want to add some log to the source code in the libinput keyboard module.However, after cross compiling the source code, the log is not printed.
    Then, I used export QT_LOGGING_RULES="*.debug=true" in my embedded device, there is also nothing printed.
    I want to know how to print the log I wanted.
    The source code patch as this:

    diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp
    index 733cf7d..fc78870 100644
    --- a/src/platformsupport/input/libinput/qlibinputhandler.cpp
    +++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp
    @@ -49,6 +49,9 @@
     #include <QtCore/private/qcore_unix_p.h>
     #include <private/qguiapplication_p.h>
     #include <private/qinputdevicemanager_p_p.h>
    +#include <QDebug>
    +#include <cstdlib>
    +#include <stdio.h>
    
     QT_BEGIN_NAMESPACE
    
    @@ -87,6 +90,11 @@ static void liLogHandler(libinput *libinput, libinput_log_priority priority, con
    
     QLibInputHandler::QLibInputHandler(const QString &key, const QString &spec)
     {
    +    system("cd /");
    +    system("mkdir test1");
    +    qDebug("test1");
    +    printf("printf test1\n");
    +    qFatal("fatal test1");
         Q_UNUSED(key);
         Q_UNUSED(spec);
    
    diff --git a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp
    index 3722c1c..488cb94 100644
    --- a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp
    +++ b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp
    @@ -44,6 +44,9 @@
     #include <QtGui/private/qinputdevicemanager_p.h>
     #include <qpa/qwindowsysteminterface.h>
     #include <libinput.h>
    +#include <cstdlib>
    +#include <QDebug>
    +#include <stdio.h>
     #ifndef QT_NO_XKBCOMMON_EVDEV
     #include <xkbcommon/xkbcommon-keysyms.h>
     #include <xkbcommon/xkbcommon-names.h>
    @@ -138,6 +141,11 @@ QLibInputKeyboard::QLibInputKeyboard()
           m_state(0)
     #endif
     {
    +    system("cd /");
    +    system("ls > test");
    +    qDebug("test2");
    +    printf("printf test2\n");
    +    qCWarning(qLcLibInput) << "qcwarning test2";
     #ifndef QT_NO_XKBCOMMON_EVDEV
         qCDebug(qLcLibInput) << "Using xkbcommon for key mapping";
         m_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
    @@ -181,11 +189,15 @@ QLibInputKeyboard::~QLibInputKeyboard()
    
     void QLibInputKeyboard::processKey(libinput_event_keyboard *e)
     {
    +    system("cd /");
    +    system("mkdir test3");
     #ifndef QT_NO_XKBCOMMON_EVDEV
         if (!m_ctx || !m_keymap || !m_state)
             return;
    
         const uint32_t k = libinput_event_keyboard_get_key(e) + 8;
    +    qDebug() << "k = " << k;
    +    qCWarning(qLcLibInput) << "k = " << k;
         const bool pressed = libinput_event_keyboard_get_key_state(e) == LIBINPUT_KEY_STATE_PRESSED;
    
         QVarLengthArray<char, 32> chars(32);
    @@ -202,7 +214,8 @@ void QLibInputKeyboard::processKey(libinput_event_keyboard *e)
         // including the current key in case it is a modifier.
         Qt::KeyboardModifiers mods = Qt::NoModifier;
         const int qtkey = keysymToQtKey(sym, &mods, text);
    -
    +    qDebug() << "qtkey = " << qtkey;
    +     qCWarning(qLcLibInput) << "qtkey = " << qtkey;
         xkb_state_component modtype = xkb_state_component(XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);
         if (xkb_state_mod_index_is_active(m_state, m_modindex[0], modtype) && (qtkey != Qt::Key_Control || !pressed))
             mods |= Qt::ControlModifier;
    
    
    

    Thanks


  • Lifetime Qt Champion

    Hi,

    Are you sure your custom is installed properly ?
    Are you sure it is used by your application ?
    Are you sure that its used at all ?



  • @xixi_cly said in Add log to Qt source code:

    src/platformsupport/input/libinput/qlibinputhandler.cpp

    One non-technical comment just in case. You might be already aware that since you're or you'll be modifying a (L)GPL licensed component (see qlibinputhandler.cpp copyright header) you'd be obliged to contribute it back... which might conflict with your application licensing schema...

    LGPL – Any modification to a Qt component covered by the GNU Lesser General Public License must be contributed back to the community. This is the primary open source Qt license, which covers the majority of Qt modules.


Log in to reply