Check the error with QT

I m getting run time error in the following program..
Plz solve this one.
Actually the runtime error comes in
view.cpp file

myview->setwindow(mywindow)

myview.h:
class QTOPENCASCADE_EXPORT View
: public QGLWidget
{
Q_OBJECT

public:

View(QWidget *parent=0);
~View();

void Initialize(Handle_AIS_InteractiveContext);//,QWidget *);

Handle_AIS_InteractiveContext getContext( void ) { return myContext; }
Handle_V3d_View getView( void ) { return myView; }

protected:

protected:

void paintEvent ( QPaintEvent * e);

private:

Handle_V3d_View myView;
Handle_AIS_InteractiveContext myContext;

public:
short hi, lo;

};

#endif // View_H

view.cpp......
#include
#include
#include "View.h"
#include "viewer.h"
#include "mainwindow.h"
#include
#include
#include
#include

View::View(QWidget *parent) : QGLWidget(parent,0,0)//Qt::SubWindow)
{
//setParent(parent);
myView = NULL;
this->setAutoFillBackground( false );
//setMaximumSize(400, 400);
//showMaximized();

//setGeometry(0,0,1024,768);

int windowHandle = 0;
windowHandle=(int) winId(); // Error comes here
lo=hi=0;

lo = (short) windowHandle;
hi = (short) ( windowHandle >> 16 );

}

View::~View()
{

}

void View::Initialize(Handle_AIS_InteractiveContext aContext)
{
myContext=0;
myContext = aContext;

myView=0;
myView = aContext->CurrentViewer()->CreateView();

Handle(WNT_Window) myWindow = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(myContext->CurrentViewer()->Device()),(int) hi,(int) lo,Quantity_NOC_BLACK);

try
{
myView->SetWindow(myWindow);// here the run time error comes

}catch(Standard_MultiplyDefined)
{ (new QMessageBox(0))->show();

}
myView->SetBackgroundColor(Quantity_NOC_BLACK);

myWindow->SetFlags(WDF_NOERASEBKGRND);
if (!myWindow->IsMapped())
myWindow->Map();

myView->DoMapping();

myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_RED, 0.08);

myView->MustBeResized();
myView->SetDegenerateModeOff();
aContext->CurrentViewer()->SetViewOn(myView);

}

void View::paintEvent ( QPaintEvent * e)
{

if (!myView.IsNull())
myView->Redraw();
//getView()->Update();

}

P Dolbey's picture

In my Qt4 code (which works) I create the view before getting the windowHandle - you can see my doxygen'd code at http://myweb.tiscali.co.uk/dolbey/QtOpenCascade/doc/html/_qt_o_c_c_view_....

The initialise routine is at line 104 (than anchor probably won't work in the URL above).

Good luck.

Pete

Rajesh Kishore's picture

Hi Pete,
I had tried it earlier and this time too, but still the run time error comes at
myView->SetWindow(myWindow); in view.cpp
Plz help me in this
Rajesh

Rajesh Kishore's picture

Hi Pete,
I had tried it earlier and this time too, but still the run time error comes at
myView->SetWindow(myWindow); in view.cpp
Plz help me in this,
I am using Qt 4.2.2 , is this could be the problem?
Rajesh

P Dolbey's picture

Rajesh

I use 4.2.2 on XP - Marc Bitten used 4.2.1 for the Linux port. I don't think the version is your problem. What's your operating system, as its not clear on the original post. You can post me a zipped copy of your sources if you want at peter(at)dolbey(dot)freeserve(dot)co(dot)uk (with the usual replacements) and I'll take a look at them.

Pete

Harsh's picture

Hi Rajesh,

I guess you have been working on Opencascade with QT 4.2.2 on Windows XP too, i have just begun working on the same platform and am receiving the same error
// myView->SetWindow(myWindow) ; in QTOCCViewWidget.cpp by Mr. Dolbey.

Could you tell me what were you doing wrong (i guess i am doing the same thing) and how did you rectify it.

Thanks in Advance
Harsh

P Dolbey's picture

Harsh,

Your not doing anything wrong as such. What we discovered was that on Rajesh's platform the winId() (a.k.a the HWND handle) had not been set in the QtOCCViewWidget::initialize() method - on my platform with an ATI X300 graphics card it was OK. We found that it was due to inheriting QtOCCViewWidget from QGLWidget.

There were discussions in other threads about this where directly inheriting from QWidget resulted in an unstable display. However I did discover a way of directly inheriting from QWidget on win32 with no problem. Unfortunately, when Marc Britten ported this code onto Linux it failed, se we went back to QGLWidget.

Fortunately I did keep the project that employed this technique and I will put it up my web site for you over the week-end (I'm still at work and can't quite remember all the changes I made). I'll add the URL to this thread. Rajesh discovered the same method on his own.

It would be interesting to know if you both have similar graphics cards - apparently the problem existed in the orginal Qt3 code as well, yet the standard Qt OpenGL examples worked fine. I could never reproduce the problem on my platform. I've now moved Qt 4.2.3, but I don't know if that will fix your problem.

Pete

P Dolbey's picture

Try this version - won't work on Unix though!

http://myweb.tiscali.co.uk/dolbey/QtOpenCascade/QtOCC-0.3.zip

Pete

Rajesh Kishore's picture

Hi Harsh,
I really struggle, i spend around two weeks to sort out my problem, but at last i could discover that while including Qglwidget.h the winid remains unused. Instead of QGlwidget.h use QWidget.h i.e inherit the Qtoccviewwidget class using QWidget class. This will sort out your problem.

Harsh's picture

Hi Pete & Rajesh,

Thanks a lot for your replies. sorry for the delayed response from my end, i was out of town for a couple of days , came back to my desk today. The code you sent Pete, is working just fine, now all i have to do is to understand the difference between the two codes and try to start implementing my own pseudo codes.

Thanks a lot again, will disturb again if i need any more help
cheers
Harsh

P Dolbey's picture

Harsh

I suspect that the problem is somewhere in the constructor for the QGLWidget, which isn't in the QWidget but as I said I can't reproduce the problem. Either that or its down different "timings" as the OpenGL context is setup on different graphics cards.

One option I'm considering is to use #ifdef WNT/LIN to switch between QGLWidget and QWidget inheritance on different platforms to keep the Linux/Unix version still running. If Marc's listening he may wish to comment.

Pete

P Dolbey's picture

I think I finally understand whats happening here. In the Qt4 QGLWidget initialisation should be performed in the subclasse's initializeGL() routine, just as it is in the Qt4 hellogl example. I think that some graphics cards must be pickier than my ATI Radeon X300, and don't like windows that haven't been shown yet, hence not giving them a HWND or winId() that can ve used with OCC.

I've now got a re-written initialisation and painting technique - if anyone's still interested post back here and I'll make it available somehow.

Pete

illusion's picture

I have the same problem with initialisation and painting using a QGLWidget. It would be great if you could provide a example of using QGLWidgets(from Qt 4.3) and OCC...Thanks in advance.

P Dolbey's picture

There's a version I've put as the current version on my site as

http://myweb.tiscali.co.uk/dolbey/QtOpenCascade/QtOCC-0.9.zip

This is using my new class names " i.e. Qocc..., not QtOCC..." and uses the intializeGL to set the OCC context in the first paintGL call. I developed it with Qt 4.3. It works on my platform, but I have not had it confirmed on cards other than ATI Radeon or on Linux yet.

Good luck with it.

Pete

Isaac Amankwaa's picture

When I try to compile that QtOCC-0.9.zip using Visual Studio 2008 and Qt Version 4.6.3, I receive the error

error C3861: 'wglGetCurrentContext': identifier not found at the line that says

rc = (Aspect_RenderingContext) wglGetCurrentContext();

in the file QoccViewWidget.cpp

Any Help will be appreciated.