Unsolved Signals and slots
-
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_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
/////////////////////////////////////////////////////////////////// -
Hi,
Looks like updatelabel doesn't have any implementation. Is that correct ?
-
@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. -
Hi
Just a thought ?class GLWidget : public QGLWidget
{
Q_OBJECT; // missing ? -
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 ? -
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")); -
@BhanuKiranChaluvadi said:
So, my SIGNAL gets emitted from glwidget.cpp and
my SLOT execution/implementation is present in mainWindow.cppyes that would be alright.