tjsail33 0 Newbie Poster

First question here, so bear with me.

I have been trying to create a view on a QMainWindow using a QDeclarativeView as the canvas, but whenever I try to switch the source of the QDeclarativeView my program segfaults and I frankly have no idea why, or how to fix it.

Here is my swapView() function.

void MainWindow::swapView(int view)
    {
     switch (view)
     {
        case 0:
            cout << "Switching to Slideshow..." << endl;
            this->setSource("Slideshow.qml");
            break;
        case 1:
            cout << "Switching to Main Canvas..." << endl;
            this->setSource("Test.qml");
            cout << "Successfully switched to Main Canvas!" << endl;
            break;
     }
    }

Here is the setSource() method that it is calling:

void MainWindow::setSource(QString fileName)
    {
        this->ui->declarativeView->setSource(QUrl::fromLocalFile("Test.qml"));
    }

I tried doing this, and it gets rid of the segfault, but each window opens in a separate window instead of just replacing the view on the QDeclarativeView.

void MainWindow::setSource(QString fileName)
    {
        QDeclarativeView *view = new QDeclarativeView;
        view->setSource(QUrl::fromLocalFile(fileName));
        ui->declarativeView = view;
        ui->declarativeView->show();
    }

If anyone has any input on what I'm doing wrong (I'm sure it's something stupid), please let me know...

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.