OpenGL을 사용하여 생성 된 삼각형과 그 삼각형 색상을 변경하는 세 개의 누름 단추가있는 간단한 응용 프로그램을 만들고 싶었습니다. 삼각형이 생성되지 않습니다하지만 불행히도 버튼이 작동하지 않습니다 내가 말하는 오류를 얻을 :Qt, OpenGL 위젯, 슬롯 없음
QObject를이 : 연결 : 없음 같은 슬롯 MainWindow를 :: redSlot (OGL)를 .. \ buttonwidget에 mainwindow.cpp \ : 17 QObject :: connect : 해당 슬롯 없음 MainWindow :: greenSlot (OGL) in .. \ buttonwidget \ mainwindow.cpp : 20 QObject :: connect : 슬롯 없음 MainWindow :: blueSlot (OGL) in .. \ buttonwidget \ mainwindow.cpp : 23
내가 가지고있는 슬롯 정의 :
void MainWindow::redSlot(Widget* w)
{
w->setColor(red);
}
void MainWindow::greenSlot(Widget* w)
{
w->setColor(green);
}
void MainWindow::blueSlot(Widget* w)
{
w->setColor(blue);
}
생성 된 삼각형의 색상을 변경하는 클래스 위젯에서 선언 된 변수를 변경하고 있습니다. 여기에 클래스 위젯의 :
class Widget : public QGLWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
QSize minimumSizeHint() const;
QSize sizeHint() const;
enum color c;
void setColor(enum color color1);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
};
그리고 나는 수업 시간에 버튼에 슬롯을 연결 MainWindow를 생성자 :
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
layout = new QVBoxLayout();
QWidget *w = new QWidget();
setCentralWidget(w);
w->setLayout(layout);
Widget *OGL = new Widget();
//OGL->c=green; - it was a test whether changing value of enum type variable c works
//it works, changing it changes the color of a generated triangle
redButton = new QPushButton(tr("Red"));
connect(redButton, SIGNAL(clicked()), this, SLOT(redSlot(OGL)));
greenButton = new QPushButton(tr("Green"));
connect(greenButton, SIGNAL(clicked()), this, SLOT(greenSlot(OGL)));
blueButton = new QPushButton(tr("Blue"));
connect(blueButton, SIGNAL(clicked()), this, SLOT(blueSlot(OGL)));
layout->addWidget(OGL);
layout->addWidget(redButton);
layout->addWidget(greenButton);
layout->addWidget(blueButton);
}
여기에 헤더 슬롯 선언입니다 :
class MainWindow : public QMainWindow
{
Q_OBJECT
QVBoxLayout *layout;
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QPushButton *redButton;
QPushButton *greenButton;
QPushButton *blueButton;
public slots:
void redSlot(Widget*);
void greenSlot(Widget*);
void blueSlot(Widget*);
};
가 어떻게 그들이 작동되도록해야합니까? QT에서
당신이'MainWindow' 헤더에 선언하기 전에 슬롯 키워드를 넣어 않았다 클린을하고 –
를 다시 한 경우에, Qt를 사용한 이후로 꽤 오랜 시간이 걸렸지 만, 나는이 오류를 모호하게 기억하고 있습니다. MOC 컴파일러를 올바르게 사용 했습니까? 헤더를'public slot :'을 사용하여 정확하게 정의 했습니까? – kroneml
홍수에 빠지기 전에 Qt 기초 지식을 배우고 자합니다 : http://qt-project.org/doc/qt-5/signalsandslots.html. 문제가있는 경우 실제 프로젝트에서 코드 조각을 게시하는 대신 SSCCE에 전체 코드를 제공해야합니다. –