Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt+VTK: build successful but run failed...
Forum Updated to NodeBB v4.3 + New Features

Qt+VTK: build successful but run failed...

Scheduled Pinned Locked Moved Installation and Deployment
12 Posts 3 Posters 8.3k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    adam-tum
    wrote on last edited by
    #1

    Hello,
    am trying to implement a main window that shows a vtk widget.
    Build is successful but run fails with no errors...Please, could you help me.
    Am using Ubuntu 11.10, Netbeans 7.0.1. & my files are look like:

    TestSoftWare.cxx:

    @#include "SoftWare.h"
    #include <QApplication>
    #include <QVTKWidget.h>
    #include <QtGui/QWidget>
    #include <vtkSmartPointer.h>
    #include <vtkSphereSource.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkActor.h>
    #include <vtkImageViewer.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkInteractorStyleImage.h>
    #include <vtkRenderer.h>
    #include <vtkJPEGReader.h>

    int main(int argc, char** argv)
    {
    QApplication app(argc, argv);
    MainWindow* mainWin;
    QVTKWidget* widget;
    mainWin->resize(256,256);

    //---vtk stuff here---//

    widget->SetRenderWindow(renderWindow);
    mainWin->show();
    app.exec();
    return EXIT_SUCCESS;
    }
    @

    SoftWare.h:

    @#ifndef SOFTWARE_H
    #define SOFTWARE_H

    #include <QMainWindow>
    class QAction;
    class QMenu;

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow();

    protected:
    void closeEvent(QCloseEvent *event);

    private slots:
    void open();

    private:
    void createActions();
    void createMenus();
    void createToolBars();
    void createStatusBar();

    QString curPath;
    QMenu *fileMenu;
    QToolBar *fileToolBar;
    QAction *openAct;
    

    };
    #endif@

    SoftWare.cpp:

    @#include "SoftWare.h"
    #include <QtGui>

    MainWindow::MainWindow()
    {
    QVTKWidget widget;
    setCentralWidget(widget);
    createActions();
    createMenus();
    createToolBars();
    createStatusBar();
    }

    void MainWindow::open()
    {
    QString fileName = QFileDialog::getOpenFileName(this, tr("Select Directory"), "/home");
    }

    void MainWindow::createActions()
    {
    openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
    connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
    }

    void MainWindow::createMenus()
    {
    fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(openAct);
    }

    void MainWindow::createToolBars()
    {
    fileToolBar = addToolBar(tr("File"));
    fileToolBar->addAction(openAct);
    }

    void MainWindow::createStatusBar()
    {
    statusBar()->showMessage(tr("Ready"));
    }@

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      Did you try debug?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adam-tum
        wrote on last edited by
        #3

        Hi Hostel,

        thanks for the idea.
        I tried debug but I always get :
        Signal received: SIGSEGV (?) with sigcode ? (?)
        From process: ?
        For program TestSoftWare, pid 7,247

        even when I skipped it, still get it & can't continue.

        Thanks for help.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hostel
          wrote on last edited by
          #4

          Run in debug mode a program step by step - maybe you will find a line which makes problem. Maybe you are using a null pointer? You have a pointer type MainWindow and QVTKWidget - did you properly create objects by new?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            adam-tum
            wrote on last edited by
            #5

            Hi Hostel,

            First of all, Happy New Year for you.

            -About creating the pointer type, I tried to write
            MainWindow* mainWin= new MainWindow();

            but I got a build error:
            undefined reference to MainWindow:MainWindow()

            -About the debug, I built with vtkdebug & then did debug with netbeans, I got the same signal error BUT with debug error:
            no registers

            this happens only in the lines:
            mainWin->resize(256,256);
            mainWin->show();

            so, when I commented these lines, it runs but of course I can't see anything (no application window).

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hostel
              wrote on last edited by
              #6

              Thanx, and Happy New Year for you too :)

              If you have in code a pointer to MainWindow without constructiong by new a object, then when you call
              @
              mainWin->resize();
              @
              then you have a SIGSEGV.

              You have to make a object.

              You should resolve a build error with 'undefined reference(...)'.

              Try solve it by:
              @
              MainWindow::MainWindow() :
              QMainWindow() // you forget about constructor of base class
              {
              -QVTKWidget widget;- // this not looks good - this should be a member in private section of class
              widget = new QVTKWidget(); // change to this
              // your code
              }
              @

              then run qmake and try build again.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                adam-tum
                wrote on last edited by
                #7

                Hello Hostel,

                Thanks alot.
                You seem an expert with coding.

                Let me tell you what I did changed, to see if I got you correctly:

                in .cpp
                @MainWindow::MainWindow() : QMainWindow()
                {
                widget = new QVTKWidget();
                }@

                in main
                @ MainWindow* mainWin = new MainWindow();@

                I did this, but still get undefined reference error.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chris H
                  wrote on last edited by
                  #8

                  Can we see the header file for your MainWindow class? In particular, how have you defined the constructor? Your error is still "Undefined reference to MainWindow::MainWindow()"?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    adam-tum
                    wrote on last edited by
                    #9

                    here is the header file.
                    exactly, this is the error.

                    @#ifndef SOFTWARE_H
                    #define SOFTWARE_H

                    #include <QMainWindow>
                    #include <QVTKWidget.h>

                    QT_BEGIN_NAMESPACE
                    class QAction;
                    class QMenu;
                    QT_END_NAMESPACE

                    class MainWindow : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    MainWindow();

                    protected:
                    void closeEvent(QCloseEvent *event);

                    private slots:
                    void open();
                    bool exportAs();
                    void about();

                    private:
                    QVTKWidget widget;

                    void createActions();
                    void createMenus();
                    void createToolBars();
                    void createStatusBar();
                    
                    void setCurrentPath(const QString &fileName);
                    QString curPath;
                    
                    QMenu *fileMenu;
                    QToolBar *fileToolBar;
                    
                    QAction *openAct;
                    QAction *exportAsAct;
                    QAction *exitAct;
                    QAction *aboutAct;
                    

                    };

                    #endif
                    @

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hostel
                      wrote on last edited by
                      #10

                      Can we see your .pro file?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        adam-tum
                        wrote on last edited by
                        #11

                        here it is:

                        @HEADERS = SoftWare.h
                        SOURCES = TestSoftWare.cpp
                        SoftWare.cpp

                        RESOURCES = application.qrc

                        install

                        target.path = $$/home/adam-linux/Documents/TestSoftWare-Debug
                        sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS application.pro images
                        sources.path = $$/home/adam-linux/Documents/TestSoftWare-Debug
                        INSTALLS += target sources@

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          Hostel
                          wrote on last edited by
                          #12

                          I don't know why this is not working. Try re-run qmake and re-build all. If not help then try remove this lines from .pro file:
                          @
                          install
                          target.path = $$/home/adam-linux/Documents/TestSoftWare-Debug
                          sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS application.pro images
                          sources.path = $$/home/adam-linux/Documents/TestSoftWare-Debug
                          INSTALLS += target sources
                          @
                          and re-run qmake and re-build all.

                          I don't have any new ideas.

                          1 Reply Last reply
                          0

                          • Login

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