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. QObject::connect: No such signal GLWidget::textChanged
QtWS25 Last Chance

QObject::connect: No such signal GLWidget::textChanged

Scheduled Pinned Locked Moved General and Desktop
qglwidget
2 Posts 2 Posters 3.6k Views
  • 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.
  • C Offline
    C Offline
    CroCo
    wrote on last edited by
    #1

    I'm moving from GLUT to Qt. I've implemented simple projects with QGLWidget. Now I would like to interact with other widgets in MainWindow. My problem is that how QGLWidget interacts with MainWindow? I'm implemented the following sample but I get this error
    QObject::connect: No such signal GLWidget::textChanged(const QString &text) in ..\KeyEvent\mainwindow.cpp:12 QObject::connect: (receiver name: 'textEdit')

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    int main(int argc, char *argv[])
    {
     QApplication a(argc, argv);
     MainWindow w;
     w.show(); 
     return a.exec();
     }
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    class GLWidget;
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private slots:
        void on_startButton_clicked();
    
    private:
        Ui::MainWindow *ui;
        GLWidget *glwidget;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        glwidget = new GLWidget;
    
    connect(    glwidget, SIGNAL(textChanged(const QString &text)),
            ui->textEdit,   SLOT(    setText(const QString &text))  );
    
    //connect(ui->startButton, SIGNAL(clicked()),
    //               glwidget,   SLOT(  print())  );
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_startButton_clicked()
    {
    }
    

    glwidget.h

    #ifndef GLWIDGET_H
    #define GLWIDGET_H
    
    #include <QTimer>
    #include <QtOpenGL/QGLWidget>
    #include <gl/GLU.h>
    #include <gl/GL.h>
    #include <QKeyEvent>
    
    class GLWidget : public QGLWidget
    {
        Q_OBJECT
    
    public:
        explicit GLWidget(QWidget *parent = 0);
        ~GLWidget();
    
    protected:
        void initializeGL();
        void paintGL();
        void resizeGL(int w, int h);
    
    //--------------( Key Event )-----------------//
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    
    signals:
    void textChanged(const QString &text);
    
    public slots:
        void print();
    
    private:
        QTimer timer;
    };
    
    #endif // GLWIDGET_H
    

    glwidget.cpp

    #include "glwidget.h"
    #include <QDebug>
    
    
    GLWidget::GLWidget(QWidget *parent)
    : QGLWidget(parent)
    

    {

    QGLFormat glFormat;
    glFormat.setDoubleBuffer(true);
    glFormat.setDepth(true);
    setFormat(glFormat);
    
    
    connect(&timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    timer.start(10);
    }
    
    GLWidget::~GLWidget()
    {
    }
    
    void GLWidget::initializeGL()
    {
        glClearColor(0,0,0,1);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING); 
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
    }
    
    void GLWidget::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glRotatef(0.5, 0, 1, 0);
    
        glBegin(GL_TRIANGLES);
            glColor3f(1.0, 0.0, 0.0);
            glVertex3f(-0.5, -0.5, 0);
            glColor3f(0.0, 1.0, 0.0);
            glVertex3f( 0.5, -0.5, 0);
            glColor3f(0.0, 0.0, 1.0);
            glVertex3f( 0.0,  0.5, 0);
        glEnd();
    }
    
    void GLWidget::resizeGL(int w, int h)
    {
        glViewport(0,0,w,h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45, (float)w/h, 0.01, 100.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(0,0,5,0,0,0,0,1,0);
    }
    
     void GLWidget::keyPressEvent(QKeyEvent *event)
     {
         qDebug() << event->text() << " is pressed ...";
         emit textChanged(event->text());
         update();
     }
    
     void GLWidget::keyReleaseEvent(QKeyEvent * event)
     {
         qDebug() << event->text() << " is released ...";
     }
    
    void GLWidget::print()
    {
        qDebug() << "print()";
        update();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You connect statement is wrong. It should be:

      connect(glwidget, SIGNAL(textChanged(QString)),
              ui->textEdit,   SLOT(setText(QString)));
      

      Never put the variable name in the SIGNAL or SLOT macros

      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
      1

      • Login

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