Lady Be Good
Lady Be Good

Reputation: 271

Qt Adding libQGLViewer

I am trying to use libQGLViewer library in Qt. I am following the official installation process. But I still have some errors in simpleViewer.h file.

C:\Users\Halil\yedekleme\Belgeler\untitled\simpleViewer.h:1: error: QGLViewer/qglviewer.h: No such file or directory
In file included from ..\untitled\simpleViewer.cpp:1:0:
..\untitled\simpleViewer.h:1:10: fatal error: QGLViewer/qglviewer.h: No such file or directory
 #include <QGLViewer/qglviewer.h>
          ^~~~~~~~~~~~~~~~~~~~~~~

I want to explain my installation process so maybe I did some mistakes.

1- I tried one Qt OpenGl examples and it worked fine.

2- I installed and unzipped the file.

3- I built the QGLViewer.pro file then copied the files QGLViewer2.dll and QGLViewer2d.dll into my System32 directory. Then I jumped the compiling.

4- I create a QWidget project and added this code to .pro file:

INCLUDEPATH += C:/Users/Halil/yedekleme/Masaüstü/libQGLViewer-2.7.2
LIBS += -LC:/Users/Halil/yedekleme/Masaüstü/libQGLViewer-2.7.2/QGLViewer -lQGLViewer2

Now as I see it sees the file because the only error I get is on the above.

And I add my all code here, maybe I made some mistakes not in the library in the code. untitled.pro


greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

SOURCES += \
    main.cpp \
    simpleViewer.cpp

HEADERS += \
    simpleViewer.h

FORMS += \
simpleViewer.ui

INCLUDEPATH += C:/Users/Halil/yedekleme/Masaüstü/libQGLViewer-2.7.2
LIBS += -LC:/Users/Halil/yedekleme/Masaüstü/libQGLViewer-2.7.2/QGLViewer -lQGLViewer2


# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp

#include <qapplication.h>

int main(int argc, char **argv) {
  // Read command lines arguments.
  QApplication application(argc, argv);

  // Instantiate the viewer.
  Viewer viewer;

  viewer.setWindowTitle("simpleViewer");

  // Make the viewer window visible on screen.
  viewer.show();

  // Run main loop.
  return application.exec();
}

simpleViewer.h


class Viewer : public QGLViewer {
protected:
  virtual void draw();
  virtual void init();
  virtual QString helpString() const;
};

simpleViewer.cpp


using namespace std;

// Draws a spiral
void Viewer::draw() {
  const float nbSteps = 200.0;

  glBegin(GL_QUAD_STRIP);
  for (int i = 0; i < nbSteps; ++i) {
    const float ratio = i / nbSteps;
    const float angle = 21.0 * ratio;
    const float c = cos(angle);
    const float s = sin(angle);
    const float r1 = 1.0 - 0.8f * ratio;
    const float r2 = 0.8f - 0.8f * ratio;
    const float alt = ratio - 0.5f;
    const float nor = 0.5f;
    const float up = sqrt(1.0 - nor * nor);
    glColor3f(1.0 - ratio, 0.2f, ratio);
    glNormal3f(nor * c, up, nor * s);
    glVertex3f(r1 * c, alt, r1 * s);
    glVertex3f(r2 * c, alt + 0.05f, r2 * s);
  }
  glEnd();
}

void Viewer::init() {
  // Restore previous viewer state.
  restoreStateFromFile();

  // Opens help window
  help();
}

QString Viewer::helpString() const {
  QString text("<h2>S i m p l e V i e w e r</h2>");
  text += "Use the mouse to move the camera around the object. ";
  text += "You can respectively revolve around, zoom and translate with the "
          "three mouse buttons. ";
  text += "Left and middle buttons pressed together rotate around the camera "
          "view direction axis<br><br>";
  text += "Pressing <b>Alt</b> and one of the function keys "
          "(<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
  text += "Simply press the function key again to restore it. Several "
          "keyFrames define a ";
  text += "camera path. Paths are saved when you quit the application and "
          "restored at next start.<br><br>";
  text +=
      "Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
  text += "<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save "
          "a snapshot. ";
  text += "See the <b>Keyboard</b> tab in this window for a complete shortcut "
          "list.<br><br>";
  text += "Double clicks automates single click actions: A left button double "
          "click aligns the closer axis with the camera (if close enough). ";
  text += "A middle button double click fits the zoom of the camera and the "
          "right button re-centers the scene.<br><br>";
  text += "A left button double click while holding right button pressed "
          "defines the camera <i>Revolve Around Point</i>. ";
  text += "See the <b>Mouse</b> tab and the documentation web pages for "
          "details.<br><br>";
  text += "Press <b>Escape</b> to exit the viewer.";
  return text;
}

Thanks for advence.

Upvotes: 1

Views: 566

Answers (1)

  1. Never touch Windows system directories. If you have to switch to admin mode, stop and don’t do it. Take those dlls out of there, the 90s were hell precisely because everyone thought this was the way to do it - when it in fact never was except for shared, installed COM servers and runtime libraries (eg C/C++ runtime).

    MS had some problem communicating this, quite clearly :( Their documentation leaves a lot of reasoning behind things unsaid, and the developers are somehow expected to divine the best practice.

    At this point, The Old New Thing blog is the de-facto canonical "do this and here's why" documentation for Windows. It's sure much nicer to read than most documentation, because the entries are almost all set as stories, and we humans have a thing for stories :) Unfortunately, there's no table of contents (as far as I can tell), but search works.

  2. When building a library, you can either build it as a part of your project (preferred) or build stand-alone and then install it somewhere. Sensibly written build scripts (be it qmake or cmake) support choosing the installation directory, and that should be somewhere in your home profile path (under %USERPROFILE%). Building as part of your project is usually much easier.

  3. Thus, add the library as a subdirectory sub-project in your main project. It will be built along with your code, and qmake will handle the minutiae. Google around on how to tell qmake to use a library target from some other target - it’s a bit convoluted because qmake doesn’t do everything needed to support it. Ideally the library being build should even rate a prl file that then is used in the project that consumes it. PRL files are an implementation detail but there’s no easy way to sweep it under the carpet in qmake. That’s why I suggest to use cmake instead, and port the library’s build script to cmake if there isn’t one. Then, using that library becomes entirely trivial - you just add its name to target_link_libraries in the consumer project, and all the other magic, such as include paths, needed compiler defines (it any), etc. get handled as necessary.

TL;DR: Don’t develop anything new using qmake. Port library build scripts to cmake if the library doesn’t provide them already. Use ninja when building cmake projects - it’s lightning fast.

Upvotes: 1

Related Questions