Home > Net >  Why does it give an error? ui->graphicsView
Why does it give an error? ui->graphicsView

Time:04-15

My goal is to print a QImage which consists of random RGB values. However, I got this error:

No member named 'graphicsView' in 'Ui::MainWindow'

My code is here:

int sizeX = 300; int sizeY = 300;

QImage img = QImage(sizeX, sizeY, QImage::Format_RGB32);
for(int i=0; i<sizeX; i  ){
    for(int j=0; j<sizeY; j  ){
        img.setPixel(i, j, qRgb(rand()%6, rand()%6, rand()%6));
    }
}
QGraphicsScene *graphic = new QGraphicsScene(this);
graphic->addPixmap(QPixmap::fromImage(img));
ui->graphicsView->setScene(graphic);
m_ig = new ImageGenerator;
connect(m_ig, &ImageGenerator::sigTest, this, &MainWindow::slotTest);

Thanks. Best regards!

CodePudding user response:

  1. Make sure that Graphics View widget is added to your MainWindow form (usually mainwindow.ui file) in Design section of QtCreator.
  2. Check if its objectName is actually graphicsView.
  3. Try to rebuild your project.
  •  Tags:  
  • qt
  • Related