PDA

View Full Version : GL app with multipleView



mickey
24th February 2006, 18:11
Hi,
I have an app with 4 view that show the same scene from diferent point of view. To do this, I create in qtDesigner a MyWidget class and I draw 4 small widget in my app. is it good? Then I saw better the constructor below and I see 'shareWidget' that I don't use! Can it be useful to me? My approch is right?


QGLWidget ( QWidget***parent = 0, const*char***name = 0, const*QGLWidget***shareWidget = 0, WFlags*f = 0 )

Thanks

axeljaeger
24th February 2006, 19:04
With the parameter "shared" you can share textures and displaylists between all sharing QGLWidgets. As I understand you, you only use on widget so it is not usefull for you. If you'd create 4 single widgets, you should pass 3 of them the remaining one to share textures and displaylists between all of them.

mickey
24th February 2006, 21:21
Ok, I prove to do this. the instruction 2 cause a strange thing on toolbar; mywidget1 is an instance of MyWidget create from qtdesigner when I draw the first widget from qtdesigner..


//main.cpp
MainForm w;
MyWidget top (&w, "TOP", w.myWidget1);
QTabWidget* qtab = new QTabWidget(&w);
qtab->addTab(&top,"top");
qtab->showPage(&top);
Is possible to do this?
Thanks..

mickey
25th February 2006, 10:00
Hi, this is my class.... (create form qtDesinger):


class MyWidget : public QGLWidget
{
Q_OBJECT
public:
MyWidget( QWidget *parent = 0, const char *name = 0, const QGLWidget* shareWidget = 0);
.............................

I code this below and compile but the widget in tab "view1" apper black. Is this below correct?


//main.cpp
MainForm w;
// Instantiate the viewers.
MyWidget top (&w, "view1", w.myWidget1); //parent, name, shared
w.tabWidget->addTab(&top,"view1");

if I insert this code below in paintGL() but it is never executes...


if (name == "view1") {
printf("hello\n");

}

Any hints? Thanks.

jacek
25th February 2006, 15:19
Try:
MyWidget top ( 0, "TOP", w.myWidget1);


if I insert this code below in paintGL() but it is never executes...


if (name == "view1") {
printf("hello\n");
}
What is the type of that name variable? QString or char *?

mickey
25th February 2006, 16:19
Hi,
It works with "&w" again. I haven't set right the gluLookAt. It works with '0' again

MyWidget top ( 0, "TOP", w.myWidget1);
but in every widget I must to retrieve the parent Mainform....in every widget constructor
I have
w= (MainForm*)this->topLevelWidget(); and not works with '0'

'name' is a char*:


MyWidget( QWidget *parent = 0, const char *name = 0, const QGLWidg.....




if (name == "view1") {

printf("hello\n");

}
why does not it work?

jacek
25th February 2006, 16:52
'name' is a char*:
...
why does not it work?
Because you are comparing pointers, not the string contents. Use:

if( qstrcmp( name, "whatever" ) == 0 ) {
// ...
}
or

if( name == QString( "whatever" ) ) {
// ...
}
or declare that name member variable (the one you use in paintGL()) as QString.

mickey
25th February 2006, 17:33
They don't compile...

if( name == QString( "whatever" ) )
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'overloaded-function' (or there is no acceptable conversion)

Others cast problem....
I code this to use value of name (name is a const!); (this work properly but I don't like)

char* n = const_cast<char*> (name);

But arise a problem.


//main.cpp
MainForm w;
MyWidget top (&w, "MY", w.myWidget1); //parent, name, shared
w.tabWidget->addTab(&top,"MY");

Inside SLOT below I need to do something similar top->updateGL()


void MainForm::updateWidgets()
{
myWidget1->updateGL();
myWidget2->updateGL();
myWidget3->updateGL();
}
I try to declare (from Designer in mainform.ui) MyWidget top; in forward declarations class MyWidget; and include a<myWidget.h> but compiler error

'MainForm::top' uses undefined class 'MyWidget'
Is possible to do this?

jacek
25th February 2006, 18:23
They don't compile...

if( name == QString( "whatever" ) )
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'overloaded-function' (or there is no acceptable conversion)

What compiler do you use? Try:
if( QString( "whatever" ) == name )


I code this to use value of name (name is a const!); (this work properly but I don't like)
char* n = const_cast<char*> (name);
Don't do this! Better use QString.


I try to declare (from Designer in mainform.ui) MyWidget top; in forward declarations class MyWidget; and include a<myWidget.h> but compiler error

'MainForm::top' uses undefined class 'MyWidget'
Is possible to do this?
Where did you add that #include <myWidget.h>? In implementation? Your life would be much easier if you were using the subclassing approach.

mickey
25th February 2006, 18:42
What compiler do you use? Try:
if( QString( "whatever" ) == name )
don't compile (microsoft)

Where did you add that #include <myWidget.h>? In implementation? Your life would be much easier if you were using the subclassing approach.
I insert #include <myWidget.h> in implementation. Why?

But then wich is the simplest way to use top instance inside MainForm member?
thanks

jacek
25th February 2006, 19:28
I insert #include <myWidget.h> in implementation. Why?
Then it's not enough, if you want to add "top" as member variable, but it won't work either, because it is a widget. You should declare top as pointer to MyWidget.


But then wich is the simplest way to use top instance inside MainForm member?
Maybe you should consider using signals and slots instead?

mickey
25th February 2006, 22:40
Sorry but cha* name give problems again:


MyWidget::MyWidget( QWidget *parent, const char *name, const QGLWidget* shareWidget)
: QGLWidget ( parent, name, shareWidget) {
setFormat(QGLFormat(DoubleBuffer | DepthBuffer));
//n = const_cast<char*> (name);
n=(QString) name;
cout << name << endl;
cout << n << endl;
}
both cout print "widget1" "widget2" "widget3" "widget4" "widget5". It seems OK!
but in PaintGL() there is:


if (n = "myWidget5") {
cout <<"myWidget5\n";
}
Every instance of widget executes cout <<"myWidget5\n";. There is something not correct in 'if' (I think). What happen?
Thanks

jacek
25th February 2006, 22:50
if (n = "myWidget5") {
Try "==".

mickey
26th February 2006, 00:44
Thanks!. I'm sorry for '==' but I'm very tired.

Then it's not enough, if you want to add "top" as member variable, but it won't work either, because it is a widget. You should declare top as pointer to MyWidget.
It works properly declaring a 'MyWidget* top' in QTDesigner; but everytime that I'd like to add a View I must open QTDesigner. A way to avoid that?
I'd like to code this below but I must to find a way to use 'top' inside MainForm members..

//main.cpp
MainForm w;
// Instantiate the viewers.
MyWidget top (&w, "myWidget5", w.myWidget1);
w.tabWidget->addTab(&top,"myWidget5");

Maybe you should consider using signals and slots instead?
In wich sense?
Thanks for all.

jacek
26th February 2006, 00:58
It works properly declaring a 'MyWidget* top' in QTDesigner; but everytime that I'd like to add a View I must open QTDesigner. A way to avoid that?
Use the subclassing approach.


I'd like to code this below but I must to find a way to use 'top' inside MainForm members..
You can avoid that by using signals and slots --- you will need the pointer to that widget only in once place (the one where you make connections).

mickey
1st March 2006, 13:02
sorry,
but when I says "use top in mainform.ui.h" I want say eg 'top->updateGL()' (I'd like to use it in all members of mainform) and I don't understand how I can use connect for this aim (i'm a newbie). The connect I think that I make it only in main.cpp (where I have the instance of top; thank you.


//main.cpp
MainForm w;
// Instantiate the viewers.
MyWidget top (&w, "myWidget5", w.myWidget1);
w.tabWidget->addTab(&top,"myWidget5");

jacek
1st March 2006, 13:52
If all of the viewers are part of main window, then you can make them member variables of that MainForm class.

You can also do something like this:
QObject::connect( &w, SIGNAL( updateViewers() ), &w, SLOT( updateGL ) );and then declare updateViewers() as MainForm signal and emit it in appropriate places.

mickey
1st March 2006, 15:16
If all of the viewers are part of main window, then you can make them member variables of that MainForm class.
my very problem is this....in every members of mainform class I can't to top.updateGL(); compiler says me that it's not a member....I declare (for my convenience) it in main.cpp.....any suggest?

jacek
1st March 2006, 15:31
my very problem is this....in every members of mainform class I can't to top.updateGL(); compiler says me that it's not a member....I declare (for my convenience) it in main.cpp.....any suggest?
Then declare that top variable as the member variable of your MainForm class.

mickey
1st March 2006, 16:10
yes,
but I coded mainform class from qtdesigner and make 'top' member of Mainform class means declare it in qtdesigner (Otherwise, I don't know how to do). So for every view that I'll add, I'll must to do this in designer. Is there a ways to avod this (to do 'top' member of MainForm class without lanch qtDesigner)?
thanks

jacek
1st March 2006, 16:32
yes,
but I coded mainform class from qtdesigner and make 'top' member of Mainform class means declare it in qtdesigner (Otherwise, I don't know how to do).
Use the subclassing approach. Read this:http://doc.trolltech.com/3.3/designer-manual-6.html