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



  • 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"));
    }@



  • Did you try debug?



  • 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.



  • 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?



  • 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).



  • 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.



  • 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.



  • 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()"?



  • 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
    @



  • Can we see your .pro file?



  • 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@



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.