c++ - 为轴添加 slider 时未定义对 main 的引用

标签 c++ qt opengl

我目前正在尝试添加 slider 以在 OpenGl/QT/C++ 中跨不同的轴移动,但在编译时出现模糊的“对 ‘main’ 的 undefined reference ”错误。这是我的主要类(class)...

我的头文件:

#include "MyWidget.h"
#ifndef MYMAIN_H
#define MYMAIN_H

class MyMain: public QObject{

    public:
    MyMain();
    int main(int argc, char *argv[]);
    MyWidget *MyWidget;

    public slots:
    void setXTranslation(int value);
};

#endif

我的源文件:

#include "MyMain.h"

 MyMain::MyMain()
 {
 }

 int MyMain::main(int argc, char *argv[]) {

     some code here...


     QSlider *xSlider = new QSlider(Qt::Vertical);
     xSlider->setRange(0, 10);

     QObject::connect(xSlider, SIGNAL(valueChanged(int)),
                 this, SLOT(setXTranslation(int)));


     some more code here.... 

     // start it running
     return app.exec();
 }
 void MyMain::setXTranslation(int value)
 {
     some more code here....
 }

最佳答案

A program shall contain a global function called main.

您可以像这样实现您的主要功能:

int main(int argc, char* argv[]) {
     return MyMain().main(argc, argv);
}

关于c++ - 为轴添加 slider 时未定义对 main 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33469935/

相关文章:

windows - 没有 QApplication 或 QCoreApplication 的信号槽连接

c++ - QApplication::exec() 拒绝返回(在控制台程序中)

c++ - 如何在没有 Qt 的情况下反序列化 QVariant 的输出

c - OpenGL 顶点数组

opengl - GLSL 从多个灯光计算颜色矢量

c++ - 是否可以在 constexpr 中使用 std::string ?

c++ - Windows 7 和 ScreenShot.cpp GDI+ PNG 问题

C++ 读/写 - RamDisk 与 RAM

c++ - 静态关键字在这里有帮助吗

c++ - 透明的 OpenGL 窗口绘制怪异