Important: Please read the Qt Code of Conduct -

QGamepad problem

  • Hi there!, I'm developing a groundstation in Qt and as a manual flight control type I'm implementing the option to use a gamepad. The problem is that I'm having a warning that I don't understand quite well where it's coming form. The warning says:

    /onecore\com\combase\objact\objact.cxx(812)\combase.dll!74BF1B90: (caller: 74BF093B) ReturnHr(1) tid(28f0) 800401F0 No se ha llamado a CoInitialize.

    Thanks in advance for your help :).

  • Lifetime Qt Champion


    When does it occur ?

  • It occurs when I run the code in debugging mode.

  • Lifetime Qt Champion

    @DavidPL it doesn't look Qt related, so it may be a message from the backend QtGamePad uses. In that case there's nothing you can do against.


  • @aha_1980 Two things I've forgotten to mention. First, this warning keeps coming out changing the number in

    ... (ReturnHr(1)) ...
    ... (ReturnHr(2)) ...
    ... (ReturnHr(3)) ...

    this warning only appears when i have my bluetooth xbox one gamepad connected to pc. When it's off, the message doesn't appear. Second, the last part of the message is in spanish sorry haha, it says:

    CoInitialize has not been called.

  • Lifetime Qt Champion


    CoInitialize is a Microsoft COM function - do you use anything in that regard? I still don't think it's from Qt.

  • @DavidPL
    Something in your code, or the code it calls, is trying to make an MS COM call. Any COM stuff requires a call to CoInitialize() before any other COM call is made, else the runtime error you see. ReturnHr (Hr == HRESULT) is such a COM call.

    You need to track down just what that is, and check the documentation or whatever for the API, to see where you need to do that, or call something which does it for you. Step through in debugger a line at a time to see when it first happens.

  • @JonB I ran the code in debugger. The message appears in one line of the .cpp file of the dialog. The .h and .cpp files of mainwindow and the dialog are the next ones:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include "serialcomm.h"
    #include "dialog_flightcontrol.h"
    #include <QSerialPortInfo>
    #include <QThread>
    namespace Ui {
    class MainWindow;
    class MainWindow : public QMainWindow
        explicit MainWindow(QWidget *parent = 0);
        void setup_serialport(const QString, int);
        void close_serialport();
    public slots:
        void commtype_changed();
        void showresponse(const QString &s);
    private slots:
        void on_pushButton_open_port_clicked();
        void on_radioButton_autonomous_toggled(bool checked);
        Ui::MainWindow *ui;
        Dialog_FlightControl *gamepad_dialog = new Dialog_FlightControl(this);
        QStringList comm_types;
        QThread *thread_serial = new QThread;
        SerialComm *serialcomm = new SerialComm;
        QString flightcontrol_type;
    #endif // MAINWINDOW_H


    #include <QDialog>
    #include "gamepad_flightcontrol.h"
    #include <QGamepad>
    #include <QThread>
    #include <QTimer>
    namespace Ui {
    class Dialog_FlightControl;
    class Dialog_FlightControl : public QDialog
        explicit Dialog_FlightControl(QWidget *parent = 0);
        void showEvent(QShowEvent *ev);
        void show_dialog();
        void setup_gamepad(QGamepad*);
    private slots:
        void setup_gamepad_dialog();
        void on_pushButton_updategamepads_clicked();
        void update_gamepadslist(QList<int> gamepads_list);
        void update_commandedcontrols(double commanded_controls[1][21]);
        void on_pushButton_connectgamepad_clicked();
        Ui::Dialog_FlightControl *ui;
        Gamepad_FlightControl *gamepad_obj = new Gamepad_FlightControl;
        QGamepad *dialog_selected_gamepad;
        QThread *thread_gamepad = new QThread;
        QTimer *timer_commandedcontrols = new QTimer(this);
        QList<int> gamepads_list;

  • @DavidPL

    The message appears in one line of the .cpp file of the dialog.

    What does this mean? You're supposed to find out what line of code it happens from, and then figure, not just say it happens?

  • @DavidPL
    The line were it fails is in the dialog_flightcontrol.cpp constructor: ui->setupUi(this);

    Sorry for dividing the messages but it don't let me post all in one because it detects them as spam.

  • @DavidPL
    OK, yeah, that's not good for diagnosis.
    I don't suppose you compiled the source code of Qt yourself, so that you can step into this line-by-line from the debugger?

  • @JonB Ok, ui->setupUi(this) directs me to the file ui_dialog_flightcontrol.h. In that file in the function retranslateUi(Dialog_FlightControl) the line;
    groupBox_gamepad->setTitle(QApplication::translate("Dialog_FlightControl", "Gamepad", nullptr));
    Do you need me to go deeper or it's okay? Sorry for bothering you with all of this and thank you very much for your patience.

  • @DavidPL
    If the line causing that CoInitialize() error message is the:

    groupBox_gamepad->setTitle(QApplication::translate("Dialog_FlightControl", "Gamepad", nullptr));

    I can't believe it's the QApplication::translate("Dialog_FlightControl", "Gamepad", nullptr) (you could try that line yourself maybe before calling ui->setupUi(this); to make sure). And groupBox_gamepad->setTitle() looks like just setting the title of some UI group box you have?

    So I really don't know where your message is coming from, or why it only shows in Debug. Does anything actually go wrong or is it just a warning message you see which you could ignore? It might be a harmless warning in debug code if stuff works OK, that happens.

    Otherwise I can only think of making sure you clear out and recompile everything consistently (e.g. debug or release).

  • @JonB Yeah groupbox_gamepad is an ui item and no, everything works fine, the message it's just a warning but I wanted to know why was happening. But it's okay haha, I don't want to bother you any more. Thanks for the help :).

  • @DavidPL
    Oh, OK, I had no idea it was just a warning, I assumed you meant it stopped your code working!

    OK, then, it's common to get & ignore error message about CoInitialize(), and that may well happen in debug build only. You sure can just ignore that one!

  • @JonB Yeah it occurs only in debug build. So perfect!! Thanks a lot.

  • I'm having the same problem with the simple gamepad example.

    What fixed the problem for you?


Log in to reply