简体   繁体   中英

Qt connection QTableWidget and QGLWidget

I am new in Qt and i stacked in a task. I created a QGLWidget and i try to connect it with a QTablewidget. I want to take a variable from QTableWidget which i want to use in order to plot in the QGLWidget. The problem is that there are two classes, one for QGLWidget and one for ui (QDialog where QTableWidget is included) and i don't know how to take input from QTableWidget. Can i use signal and slot or i could have access in ui from QGLWidget and how can i do it? I would appreciate any thoughts.

You can do this without signal and slot. Use setter, you can set different types of variables and use it inside GLWidget :

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <QDebug>

class GLWidget : public QGLWidget

{
    Q_OBJECT
public:
    explicit GLWidget(QWidget *parent = 0);

    void setValue(int i);

signals:

public slots:

private:
    int member;

};

#endif // GLWIDGET_H

Cpp:

#include "glwidget.h"

GLWidget::GLWidget(QWidget *parent) :
    QGLWidget
    (parent)
{
}

void GLWidget::setValue(int i)
{
    member = i;
    qDebug() << i;
}

Usage:

void MainWindow::on_tableWidget_clicked(const QModelIndex &index)
{

    GLWidget *wgt = new GLWidget;
    wgt->setValue(index.data().toInt());
    wgt->show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM