PDA

View Full Version : update the view dynamically



rimie23
9th June 2012, 21:51
Hi, i returned with new problem
as you know i have like that
in the main i make


#include <QApplication>
#include "my_interface.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow window;
window.show();
window.setViewNum(1);//or window.setViewNum(4);

return app.exec();
}


in mainwindow.h i make like that


class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
void setViewNum(int num);

and in the .cpp


MainWindow::MainWindow()
{

mQOgreWidget = new QOgreWidget(this);

setCentralWidget(mQOgreWidget);

if(mQOgreWidget->isVisible())
mQOgreWidget->setViewNum(1);//or mQOgreWidget->setViewNum(4);

}

and in QOgreWidget.h

public slots :
void setViewNum(int num);
void setCameraPosition(const Ogre::Vector3 &pos);

in QOgreWidget.cpp


void QOgreWidget::setViewNum(int num)
{
if(num == 1)
{

QWidget *central0 = new QGroupBox("My Scene", this);
float wi0=central0->width();
float hi0=central0->height();

QOgreRenderWindow * orw0 = new QOgreRenderWindow(QString("View2"),mSceneMgr,mRoot,nb_cam,wi0,hi0);

QHBoxLayout* Layout0 = new QHBoxLayout();
Layout0->addWidget(orw0);

central0->setLayout(Layout0);


mVerticalLayout->addWidget(central0);

}
if(num == 4)
{

QHBoxLayout* mainlayout = new QHBoxLayout();

QGridLayout* rightSide = new QGridLayout;
/////////////////////////////////////////////////////////////////////////////////////////
QWidget *central = new QGroupBox("My Scene", this);
//QLabel* orw = new QLabel("i am",central);
float wi=central->width();
float hi=central->height();
QOgreRenderWindow *orw = new QOgreRenderWindow(QString("View0"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw);
mainlayout->addWidget(orw);
central->setLayout(mainlayout);
/////////////////////////
QWidget *central1 = new QGroupBox("0,0", this);
float wi1=central1->width();
float hi1=central1->height();
QOgreRenderWindow * orw1 = new QOgreRenderWindow(QString("View1"),mSceneMgr,mRoot,nb_cam,wi1,hi1);
mQOgreRenderWindowList.append(orw1);


QHBoxLayout* Layout1 = new QHBoxLayout();
Layout1->addWidget(orw1);
central1->setLayout(Layout1);
/****************************/
QWidget *central2 = new QGroupBox("0,1", this);
wi=central2->width();
hi=central2->height();

QOgreRenderWindow *orw2 = new QOgreRenderWindow(QString("View2"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw2);
QHBoxLayout* Layout2 = new QHBoxLayout();
Layout2->addWidget(orw2);
central2->setLayout(Layout2);



////////////////////////////////////////////////////////////////////*
QWidget *central3 = new QGroupBox("0,2", this);
wi=central3->width();
hi=central3->height();

QOgreRenderWindow * orw3 = new QOgreRenderWindow(QString("View3"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw3);
QHBoxLayout* Layout3 = new QHBoxLayout();
Layout3->addWidget(orw3);
central3->setLayout(Layout3);
/////////////////////////////////////////////////////////
QWidget *central4 = new QGroupBox("1,0", this);
wi=central4->width();
hi=central4->height();

QOgreRenderWindow *orw4 = new QOgreRenderWindow(QString("View4"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw4);
QHBoxLayout* Layout4 = new QHBoxLayout();
Layout4->addWidget(orw4);
central4->setLayout(Layout4);
////////////////////////////////////////////
QWidget *central5 = new QGroupBox("1,1", this);
wi=central5->width();
hi=central5->height();
// QLabel* orw5 = new QLabel("i am4",central3);
QOgreRenderWindow *orw5 = new QOgreRenderWindow(QString("View5"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw5);
QHBoxLayout* Layout5 = new QHBoxLayout();
Layout5->addWidget(orw5);
central5->setLayout(Layout5);
/////////////////////////////////////////
QWidget *central6 = new QGroupBox("1,2", this);
wi=central6->width();
hi=central6->height();
//QLabel* orw3 = new QLabel("i am4",central3);
QOgreRenderWindow *orw6 = new QOgreRenderWindow(QString("View6"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw6);
QHBoxLayout* Layout6 = new QHBoxLayout();
Layout6->addWidget(orw6);
central6->setLayout(Layout6);
////////////////////////////////////////////
QWidget *central7 = new QGroupBox("2,0", this);
wi=central7->width();
hi=central7->height();
//QLabel* orw = new QLabel("i am4",central7);
QOgreRenderWindow *orw7 = new QOgreRenderWindow(QString("View7"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw7);
QHBoxLayout* Layout7 = new QHBoxLayout();
Layout7->addWidget(orw7);
central7->setLayout(Layout7);
////////////////////////////////////////////////////////////
QWidget *central8 = new QGroupBox("2,1", this);
wi=central8->width();
hi=central8->height();
// QLabel* orw3 = new QLabel("i am4",central8);
QOgreRenderWindow *orw8 = new QOgreRenderWindow(QString("View8"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw8);
QHBoxLayout* Layout8 = new QHBoxLayout();
Layout8->addWidget(orw8);
central8->setLayout(Layout8);
/////////////////////////////////////////////////////////////
QWidget *central9 = new QGroupBox("2,2", this);
wi=central9->width();
hi=central9->height();
// QLabel* orw3 = new QLabel("i am4",central9);
QOgreRenderWindow *orw9 = new QOgreRenderWindow(QString("View9"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw9);
QHBoxLayout* Layout9 = new QHBoxLayout();
Layout9->addWidget(orw9);
central9->setLayout(Layout9);
///////////////////////////////////////////////
QWidget *central10 = new QGroupBox("3,0", this);
wi=central10->width();
hi=central10->height();
//QLabel* orw3 = new QLabel("i am4",central10);
QOgreRenderWindow *orw10 = new QOgreRenderWindow(QString("View10"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw10);
QHBoxLayout* Layout10 = new QHBoxLayout();
Layout10->addWidget(orw10);
central10->setLayout(Layout10);

////////////////////////////////////////////////////
QWidget *central11 = new QGroupBox("3,1", this);
wi=central11->width();
hi=central11->height();
// QLabel* orw3 = new QLabel("i am4",central11);
QOgreRenderWindow *orw11 = new QOgreRenderWindow(QString("View111"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw11);
QHBoxLayout* Layout11 = new QHBoxLayout();
Layout11->addWidget(orw11);
central11->setLayout(Layout11);
///////////////////////////////
QWidget *central12 = new QGroupBox("3,2", this);
wi=central12->width();
hi=central12->height();
// QLabel* orw3 = new QLabel("i am4",central11);
QOgreRenderWindow *orw12 = new QOgreRenderWindow(QString("View12"),mSceneMgr,mRoot,nb_cam,wi,hi);
mQOgreRenderWindowList.append(orw12);
QHBoxLayout* Layout12 = new QHBoxLayout();
Layout12->addWidget(orw12);
central12->setLayout(Layout12);
////////////////////////////////////////////////
rightSide->addWidget(/*new QGroupBox("0,0"), 0, 0 */central1,0,0);
rightSide->addWidget(central2,0,1);
rightSide->addWidget(central3,0,2);
rightSide->addWidget(central4, 1, 0 );
rightSide->addWidget(central5, 1, 1 );
rightSide->addWidget(central6, 1, 2 );
rightSide->addWidget(central7, 2, 0 );
rightSide->addWidget(central8, 2, 1 );
rightSide->addWidget(central9, 2, 2 );
rightSide->addWidget(central10, 3, 0 );
rightSide->addWidget(central11, 3, 1 );
rightSide->addWidget(central12, 3, 2 );


mVerticalLayout->addWidget(central);
mVerticalLayout->addLayout(rightSide);


}
for(int i = 0;i<mQOgreRenderWindowList.count();i++)
{
connect(mQOgreRenderWindowList[i],SIGNAL(keyPress(QKeyEvent*)),this,SLOT(keyPress(Q KeyEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(keyRelease(QKeyEvent*)),this,SLOT(keyRelea se(QKeyEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mouseP ress(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mous eRelease(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMo ve(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWhee lEvent*)));
}

}


as you know that work
Now i add this function "setCameraPosition" that work too (it add to me an object )
The question or the problem now
1-i want when i execute ""setCameraPosition"" i add than view
is it possible ?
that mean i
i want in the start of the program i see only the left view (i execute only)


QOgreRenderWindow *orw = new QOgreRenderWindow(QString("View0"),mSceneMgr,mRoot,nb_cam,wi,hi);

and in each time and when i execute "setCameraPosition" i apply

QOgreRenderWindow *orw = new QOgreRenderWindow(QString("View0"),mSceneMgr,mRoot,nb_cam,wi,hi);
and put it in the layout

amleto
10th June 2012, 11:04
aren't you also dreamvig?



and in each time and when i execute "setCameraPosition" i apply

QOgreRenderWindow *orw = new QOgreRenderWindow(QString("View0"),mSceneMgr,mRoot,nb_cam,wi,hi);

and put it in the layout


Ok, so make a slot, put that code in the slot. What are you waiting for?

rimie23
10th June 2012, 12:32
What i make as slot ? all this function ?


void QOgreWidget::setViewNum(int num)

amleto
10th June 2012, 12:44
are you also dreamvig?

rimie23
10th June 2012, 13:19
yes , i explained to you why i have two account

amleto
10th June 2012, 13:26
What do you want to happen when you push the button?

figure that out, and put it in a slot.

rimie23
10th June 2012, 14:59
yes
it work thanks

wysota
10th June 2012, 21:27
yes , i explained to you why i have two account

Please explain it to me too, otherwise I'll have to delete one of your accounts.

rimie23
10th June 2012, 21:41
Please explain it to me too, otherwise I'll have to delete one of your accounts.
OK , delete "dreamvig"
i can make it but i found that there is problem
that's the code
in mainwindow


connect(page_14, SIGNAL(coordinateChanged(const Ogre::Vector3&)),
mQOgreWidget , SLOT(setCameraPosition(const Ogre::Vector3&)));

in "setCameraPosition"


void QOgreWidget::setCameraPosition(const Ogre::Vector3 &pos)
{
central1 = new QGroupBox("Camera"+nbv, this);
float wi1=central1->width();
float hi1=central1->height();
orw1 = new QOgreRenderWindow(QString("View"+nbv),mSceneMgr,mRoot,nb_cam,wi1,hi1, mNode,pos,nodeM);
mQOgreRenderWindowList.append(orw1);
nbv++;

Layout1 = new QHBoxLayout();
Layout1->addWidget(orw1);
central1->setLayout(Layout1);

rightSide->addWidget(central1,ligne,colon);
colon++;
if(colon==3)
{
colon=0;
ligne++;
}♣
}

but when i run i look that the name of group box is
if i execute 1 time "setCameraPosition" : amera
the seconde one // : mera
3 time: era
4 time: ra
5 :a
and it make exeption when i want add the 6 th

and that waht i see when idebug


"View0", 3863365216x3863365216 windowed miscParams: externalWindowHandle=2688834
21:56:01: GLRenderSystem::_createRenderWindow "iew", 3863365216x3863365216 windowed miscParams: externalWindowHandle=2032484
21:56:03: GLRenderSystem::_createRenderWindow "ew", 3863365216x3863365216 windowed miscParams: externalWindowHandle=133000
21:56:05: GLRenderSystem::_createRenderWindow "w", 3863365216x3863365216 windowed miscParams: externalWindowHandle=133004
21:56:09: GLRenderSystem::_createRenderWindow "", 3863365216x3863365216 windowed miscParams: externalWindowHandle=198516
21:56:11: OGRE EXCEPTION(2:InvalidParametersException): Window with name '' already exists in GLRenderSystem::_createRenderWindow at ..\..\..\..\..\RenderSystems\GL\src\OgreGLRenderSy stem.cpp (line 986)


EDIT

it work now thanks ror ameleto

orw1 = new QOgreRenderWindow(QString ("View %0").arg(nbv)

amleto
10th June 2012, 23:20
This,
"Camera"+nbv

probably doesnt do what you think - you are adding a number to a pointer.

rimie23
10th June 2012, 23:31
yes for that i change and i make like that
(QString ("View %0").arg(nbv)
that work