Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating a cubeview object (qt3d) in mainWindow.cpp file

Creating a cubeview object (qt3d) in mainWindow.cpp file

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 947 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.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by
    #1

    @#include <QApplication>
    #include<mainwindow.h>
    #include <iostream>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    MainWindow mainWin;
    mainWin.resize(800, 600);
    mainWin.show();
    return app.exec();
    }
    @
    And my MainWindow .cpp file
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "cubeview.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    CubeView view;
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    But, I get a runtime error when i try to to create a cubeview class object in my mainwindow.cpp file

    Cubeview is a graphics class which creates(one that comes with qt3d) cube on scree. This object works perfectly when created in the main.cpp file. What is the problem here?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sunil.nair
      wrote on last edited by
      #2

      I found an answer. We cannot create the object in a loop of a slot.

      @

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      view=0;
      //create the icons for all the UI push button and resize the buttons
      ui->pushButton->setIcon(QIcon(":/pattern4.jpg"));
      ui->pushButton->resize(buttonsize);
      }

      void MainWindow::on_pushButton_clicked()
      {
      //if this is the first button to be clicked on the UI
      if(view==NULL)
      {
      view=new CubeView(ui->centralwidget);
      view->begin(4);
      view->resize(800, 600);
      view->show();
      }
      //for all later clicks
      else if(view!=NULL)
      {
      std::cout<<"A window is already open"<<std::endl;
      view->close();//close the already open window
      view->begin(4);//begin graphics & haptics loop
      view->resize(800, 600);
      view->show();
      }
      }

      MainWindow::~MainWindow()
      {
      delete ui;
      if(view!=NULL){
      std::cout<<"view object deleted"<<std::endl;
      delete view;}
      ;
      }
      @

      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