Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Qt Events
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Qt Events

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    horHay
    wrote on last edited by
    #1

    Hi there. I'm using Qt's drag and drop method and I want to know how do I create event handlers for events such as button clicks, combo box changes etc. I'm new to this so be nice! :D

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly do you want do drag and drop ?

      Did you take a look at the "Drag And Drop" chapter of Qt's documentation ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        horHay
        wrote on last edited by
        #3

        I've sorted the events side, but have come across this issue;

        error: uninitialized reference member 'Widget::handler' [-fpermissive]
        Widget::Widget(QWidget *parent) :
        ^

        this is after adding an event handler for "on_comboBox_currentIndexChanged(int index)
        "

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hi,
          You do not need an eventhandler for any widget that is clicked/changed or what ever you want to do with it. In basic Qt has two way of doing things. First is the event handler catch way (like the drag and drop events). You catch the event when the OS/Qt issues it in a certain widget.
          The other is to connect widgets modify/edit/change and all other kind of widgets to slots. This is called the Signal/Slot method. This is well documented in the Qt docs.
          What you described in your second post is a Signal/Slot member function going bad. Show the code of your slot and we might be able to help.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • H Offline
            H Offline
            horHay
            wrote on last edited by
            #5

            this is the code;
            @
            void Widget::on_comboBox_currentIndexChanged(int index)
            {
            for(std::vectorSDI::navalVessels*::const_iterator i = handler.ships.begin(); i != handler.ships.end(); ++i)
            {
            SDI::navalVessels* ship = *i;
            QString qstr = QString::fromStdString(ship->name);
            QString str = ui->comboBox->currentText();
            if (str == qstr)
            {
            Widget::dataInsertion(ship);
            }
            }

            }

            and the header file for widget;

            #ifndef WIDGET_H
            #define WIDGET_H

            #include <QWidget>
            #include "shipHandler.h"

            namespace Ui
            {
            class Widget;
            }

            class Widget : public QWidget
            {
            Q_OBJECT

            public:
            explicit Widget(QWidget parent = 0);
            ~Widget();
            void populateCombo();
            void getList(SDI::shipHandler& shipHandler);
            void dataInsertion(SDI::navalVessels
            ship);
            private slots:

            void on_comboBox_currentIndexChanged(int index);
            
            void on_pushButton_clicked();
            

            private:
            Ui::Widget *ui;
            SDI::shipHandler& handler;
            };

            #endif // WIDGET_H
            @

            [edit: add missing @ coding tags SGaist]

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @if (str == qstr)
              {
              Widget::dataInsertion(ship); << You are calling it like it's static function which it's not
              }
              @

              @
              private:
              Ui::Widget *ui;
              SDI::shipHandler& handler; << is a reference. Why ?
              @

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • JeroentjehomeJ Offline
                JeroentjehomeJ Offline
                Jeroentjehome
                wrote on last edited by
                #7

                Hi,
                Do you set the SDI::shipHandler& handler to a valid value in the constructor of you Widget class??? The compiler bugs you that you are using an uninitialized variable. The on_comboBox_ function is probably the first that uses that variable.

                Greetz, Jeroen

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  horHay
                  wrote on last edited by
                  #8

                  I've sorted this error, it was because i was assigning a reference not initialising it. Thank you for your time people

                  1 Reply Last reply
                  0
                  • JeroentjehomeJ Offline
                    JeroentjehomeJ Offline
                    Jeroentjehome
                    wrote on last edited by
                    #9

                    Please place [SOLVED] in front of your first post!

                    Greetz, Jeroen

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved