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. Signals and slots
Forum Updated to NodeBB v4.3 + New Features

Signals and slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 2.0k Views 2 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.
  • BhanuKiranChaluvadiB Offline
    BhanuKiranChaluvadiB Offline
    BhanuKiranChaluvadi
    wrote on last edited by
    #1

    I am using a trying to create a touch pad event . In my UI i have a widget and label . When ever i swipe on the widget the label text should change.

    I promote widget present in the UI to glwidget that i created.

    I defined my signal in glwidget.h as void updatelabel()
    and i am trying to emit updatelabel() in glwidget.cpp in one of the member functions.

    Errors: glwidget.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl GLWidget::updatelabel(void)" (?updatelabel@GLWidget@@QEAAXXZ) referenced in function "public: virtual bool __cdecl GLWidget::event(class QEvent *)" (?event@GLWidget@@UEAA_NPEAVQEvent@@@Z)

    Secondly my "connect" statement in mainWindow.cpp is it correct ? (because label->setText takes input Qstring which should take input as "hello" rather than simple hello)

    If i want to define my own slot where should is define it because i have to access "ui->label->setText "

    I create 5 Files:
    glwidget.h
    glwidget.cpp
    mainWinodw.h
    mainWindow.cpp
    main.cpp

    //////////////////////////////////////////glwidget.h///////////////////////////////
    #ifndef GLWIDGET_H
    #define GLWIDGET_H

    #include<QGLWidget>
    #include <QEvent>
    #include<mainwindow.h>

    class GLWidget : public QGLWidget
    {
    public:
    explicit GLWidget(QWidget *parent = 0);
    bool event(QEvent *event);

    signals:
    void updatelabel();
    };

    #endif // GLWIDGET_H

    ////////////////////////////////////////////////////////////// glwidget.cpp///////////////////////////////
    #include "glwidget.h"

    GLWidget::GLWidget(QWidget *parent)
    {
    //setAttribute(Qt::WA_AcceptTouchEvents, true);
    }

    bool GLWidget::event(QEvent *e)
    {
    emit updatelabel();
    qInfo("Event Entered");
    switch(e->type())
    {
    case QEvent::TouchBegin:
    qInfo("TouchBegin Event occured");
    emit updatelabel();
    return true;
    case QEvent::TouchUpdate:
    qInfo("TouchUpdate Event occured");
    return true;
    case QEvent::TouchEnd:
    qInfo("TouchEnd Event occured");
    return true;
    default:
    qInfo("No touch Event occured");
    return QWidget::event(e);
    }
    }
    //////////////////////////////////////////////////////////////////mainWindow.cpp//////////////////////////////////
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    setAttribute(Qt::WA_AcceptTouchEvents, true);
    connect(ui->GLwidget, SIGNAL(update_label()), ui->label, SLOT(setText(hello)));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::execute()
    {
    ui->label->setText("Hello!! Finally");
    }

    ///////////////////////////////////////////////////////////////////mainWindow.h/////////////////////////////
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <glwidget.h>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    ///////////////////////////////////////////////////////////////////

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

      Hi,

      Looks like updatelabel doesn't have any implementation. Is that correct ?

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

      BhanuKiranChaluvadiB 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Looks like updatelabel doesn't have any implementation. Is that correct ?

        BhanuKiranChaluvadiB Offline
        BhanuKiranChaluvadiB Offline
        BhanuKiranChaluvadi
        wrote on last edited by
        #3

        @SGaist
        Hi,
        I am worried about the Error
        Errors: glwidget.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl GLWidget::updatelabel(void)" (?updatelabel@GLWidget@@QEAAXXZ) referenced in function "public: virtual bool __cdecl GLWidget::event(class QEvent *)" (?event@GLWidget@@UEAA_NPEAVQEvent@@@Z)

        Error is occuring because of the line "emit updatelabel()" in GLWidget.cpp

        In mainWindow.cpp there is statement
        connect(ui->GLwidget, SIGNAL(update_label()), ui->label, SLOT(setText(hello)));
        Isn't setText(hello) is implementation.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Just a thought ?

          class GLWidget : public QGLWidget
          {
          Q_OBJECT; // missing ?

          BhanuKiranChaluvadiB 1 Reply Last reply
          4
          • mrjjM mrjj

            Hi
            Just a thought ?

            class GLWidget : public QGLWidget
            {
            Q_OBJECT; // missing ?

            BhanuKiranChaluvadiB Offline
            BhanuKiranChaluvadiB Offline
            BhanuKiranChaluvadi
            wrote on last edited by
            #5

            Hi @mrjj Thanks for the response.

            I have few more doubts. In mainWindow.cpp
            connect(ui->GLwidget, SIGNAL(update_label()), ui->label, SLOT(setText(hello)));

            Do i need to implement function in the slot ?

            In another case if i want to define my own slot function : For example
            SLOT(changeLabel)

            changeLabel (Qstring xyz)
            {
            ui->Label->setText(xyz)
            }

            Where should i declare and implement this SLOT ?
            (I have 5 files glwidget.h , glwidget.cpp, mainWindow.h, mainWindow.cpp, main.cpp)

            since i have to access "ui->label" i guessing i should define the function in mainWindow.cpp

            So, my SIGNAL gets emitted from glwidget.cpp and
            my SLOT execution/implementation is present in mainWindow.cpp
            Is that alright ?

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

              Hi
              There is something wrong here
              connect(ui->GLwidget, SIGNAL(update_label()), ui->label, SLOT(setText(hello)));

              update_label do not have a QString as parameter so you cannot call setText as the "hello" have no where to come from.

              so it should be defined af
              signals:
              void updatelabel(QString);

              and u should emit with text
              emit updatelabel(QString("HELLO"));

              mrjjM 1 Reply Last reply
              4
              • mrjjM mrjj

                Hi
                There is something wrong here
                connect(ui->GLwidget, SIGNAL(update_label()), ui->label, SLOT(setText(hello)));

                update_label do not have a QString as parameter so you cannot call setText as the "hello" have no where to come from.

                so it should be defined af
                signals:
                void updatelabel(QString);

                and u should emit with text
                emit updatelabel(QString("HELLO"));

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @BhanuKiranChaluvadi said:

                So, my SIGNAL gets emitted from glwidget.cpp and
                my SLOT execution/implementation is present in mainWindow.cpp

                yes that would be alright.

                1 Reply Last reply
                1

                • Login

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