[Qt-interest] Screen Getting White

Sujan Dasmahapatra sdh at lmglasfiber.com
Tue Apr 21 14:29:27 CEST 2009


Dear Friends 

I am into the development of an engineering software where I am loading
multiple geometries from the  QFileDialog and displaying them on the
main window and at the same time the file names are being uploaded onto
the QTableWdiget one by one. I am using a QGraphicsScene and
QGraphicsView which is used for display, the default Scene color is
black..Everything is going fine but sometimes when I load a geometry the
screen is getting white and no geometries are found.But actually the
geometries  are there  and filename is nicely uploaded in my
QTableWidget. If I continue the operation and if I load another geometry
next then all the geometries are coming back on the screen and all are
visible.I am facing this problem severely.

                I thought that I am  not refreshing the screen during
and after loading the geometry so I am calling  "qApp->processEvents()"
before and after loading the geometry as one of our friends suggested
but it's still happening and I am fade up with this bug.Please help me
somebody.

 

Some codes I am writing here for understanding.

////////////////////////////////////////////Scene and View
Management///////////////////////

        scene = new GraphicsScene;

        view = new QGraphicsView(scene);

        view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView,"Geometry
View"));

        view->setGeometry(250,70,1020,646);

        view->setParent(this,Qt::SubWindow);

        scene->setParent(view);

/////////////////////////loading
geometry/////////////////////////////////////////////////////////

void MainWindow::open()

{

    qApp->processEvents();

    int i;

    xmax=0.0,xmin=0.0,ymax=0.0,ymin=0.0;

    fileopendialog.setAcceptMode(QFileDialog::AcceptOpen);

        if(fileopendialog.exec())

        {

                Filenames = fileopendialog.selectedFiles();

        }

    if(Filenames[0].isEmpty())

        return;

 

    if(fileopendialog.result()==QDialog::Rejected)

        return;

 

    if(!firstTime)

    {

    if(tableWidget->countTableWidget == 0)

        {

        countMainWindow = 0;

        fileGeometry.clear();

        geometry.clear();

        }

    }

    if(fileopendialog.selectedNameFilter()=="*.dat")

   {

    fileGeometry.append(Filenames[0]);

    QFile file(fileGeometry[countMainWindow]);

    file.open(QIODevice::ReadOnly);

    QTextStream  stream(&file);

    QString ch;

        ch = stream.read(2);

        stream >> numberOfPoints;

        x =new double[numberOfPoints];

        y = new double[numberOfPoints];

        QPointF *dataPoints = new QPointF[numberOfPoints];

        for(i = 0; i< numberOfPoints; i++)

        {

                stream >> x[i] >> y[i];

               dataPoints[i].setX(x[i]);

                dataPoints[i].setY(y[i]);

 

        }

        xmax = dataPoints[0].x();

 

        for(i=1; i<=numberOfPoints; i++)

        {

                if(dataPoints[i].x() > xmax)

                                xmax = dataPoints[i].x();

        }

 

        xmin = dataPoints[0].x();

 

        for(i=1; i<=numberOfPoints; i++)

        {

                if(dataPoints[i].x() <  xmin )

                                xmin = dataPoints[i].x();

        }

 

        width = xmax-xmin;

        if(width <0.0)

                width = width * (-1.0);

 

        ymax = dataPoints[0].y();

 

        for(i=1; i<=numberOfPoints; i++)

  {

                if(dataPoints[i].y() > ymax)

                             ymax = dataPoints[i].y();

        }

 

        ymin = dataPoints[0].y();

 

        for(i=1; i<=numberOfPoints; i++)

        {

                if(dataPoints[i].y() < ymin)

                                ymin = dataPoints[i].y();

        }

 

        height = ymax-ymin;

        if(height < 0.0)

                height = height * (-1.0);

     geometry.append(new Geometry(numberOfPoints,dataPoints));

     file.close();

     delete x;

     delete y;

     }

    else if(fileopendialog.selectedNameFilter()=="*.tyk")

    {

                fileGeometry.append(Filenames[0]);

                QFile filetykread(fileGeometry[countMainWindow]);

                filetykread.open(QIODevice::ReadOnly);

                QTextStream stream(&filetykread);

                stream >> numberOfPoints;

                numberOfPoints = numberOfPoints;

                double *xval = new double[numberOfPoints];

                double *ytop = new double[numberOfPoints];

                double *ybot = new double[numberOfPoints];

                for(i=0; i<numberOfPoints; i++)

                {

                        stream >> xval[i] >> ytop[i] >> ybot[i];

                }

 

                numberOfPoints = (2*numberOfPoints);

                x = new double[numberOfPoints-1];

                y = new double[numberOfPoints-1];

                QPointF *dataPoints = new QPointF[numberOfPoints-1];

 

                for(i=0; i<(numberOfPoints-1); i++)

                {

                        if(i<=(numberOfPoints/2)-1)

                        {

                                x[i] = xval[(numberOfPoints/2)-1-i];

                                y[i] = ybot[(numberOfPoints/2)-1-i];

                        }

                        if(i>=numberOfPoints/2)

                        {

                                x[i] = xval[i-(numberOfPoints/2)+1];

                                y[i] = ytop[i-(numberOfPoints/2)+1];

                        }

                }

               for(i=0; i<(numberOfPoints-1);i++)

                {

                        dataPoints[i].setX(x[i]);

                        dataPoints[i].setY(y[i]);

                }

        xmax = dataPoints[0].x();

 

        for(i=1; i<=numberOfPoints; i++)

        {

                if(dataPoints[i].x() > xmax)

                                xmax = dataPoints[i].x();

        }

 

xmin = dataPoints[0].x();

 

        for(i=1; i<=numberOfPoints; i++)

        {

                if(dataPoints[i].x() <  xmin )

                                xmin = dataPoints[i].x();

        }

 

        width = xmax-xmin;

        if(width <0.0)

                width = width * (-1.0);

 

        ymax = dataPoints[0].y();

 

        for(i=1; i<=numberOfPoints; i++)

        {

              if(dataPoints[i].y() > ymax)

                                ymax = dataPoints[i].y();

        }

 

        ymin = dataPoints[0].y();

 

        for(i=1; i<=numberOfPoints; i++)

        {

                if(dataPoints[i].y() < ymin)

                                ymin = dataPoints[i].y();

        }

 

        height = ymax-ymin;

        if(height < 0.0)

                height = height * (-1.0);

     geometry.append(new Geometry(numberOfPoints-1,dataPoints));

     filetykread.close();

     delete xval;

     delete ytop;

     delete ybot;

     delete x;

     delete y;

    }

  else

   {

        statusBar()->showMessage(tr("Unknown format"),2000);

   }

     qApp->processEvents();

     scene->addItem(geometry[countMainWindow]);

     tableWidget->fileNameUpdate(fileGeometry[countMainWindow],
geometry[countMainWindow]);

     view->fitInView(geometry[countMainWindow],Qt::KeepAspectRatio);
//This two functions are fitting the geometry on the view

     view->setSceneRect(xmin,-ymax,width,height);

     view->show();

     statusBar()->showMessage(tr("Part loaded"),2000);

     consoleView->append(fileGeometry[countMainWindow] + " is loaded");

     countMainWindow++;

     firstTime = false;

     qApp->processEvents();

 

}

 

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

 

 

 

Kind regards, 
LM Glasfiber R&D (India) Pvt. Ltd.
 
Sujan Dasmahapatra
Project Engineer - CFD
  
Telephone: +91 80 66470248 
Mobile: 
E-mail: sdh at lmglasfiber.com <mailto:sdh at lmglasfiber.com>  

 

 

 

 

--------------------------------------------------------------

This e-mail and any attachments are confidential. If you are not the
named or intended recipient, please notify the sender immediately and do
not disclose the contents to any other person, use it for any purpose or
store or copy the information in any medium. Any unauthorized
disclosure, use or storage is prohibited and might be unlawful.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090421/5fa7d2f8/attachment.html 


More information about the Qt-interest-old mailing list