alicevision / MeshroomMaya

Photomodeling plugin for Maya
http://alicevision.org
Mozilla Public License 2.0
140 stars 34 forks source link

Error: QApplication before a QWidget #202

Open akuzminykh opened 4 years ago

akuzminykh commented 4 years ago

I've compiled the plug-in, made all dependencies (.dlls) available and imported it successfully into Maya. Sadly, when I open the plug-in from the menu Maya crushes. I've checked the dump file and the error does occur because of a null pointer. Then I've rebuilt the plug-in in debug mode and watched maya.exe at runtime with the Visual Studio debugger.

I've found the exact errors:

QWidget: Must construct a QApplication before a QWidget

and

QWidget: Cannot create a QWidget without QApplication

The file with the error is this:

#include "meshroomMaya/qt/MVGMainWidget.hpp"
#include "meshroomMaya/qt/QmlInstantCoding.hpp"
//#include "meshroomMaya/qt/QWheelArea.hpp"
#include "meshroomMaya/maya/MVGMayaUtil.hpp"
#include "meshroomMaya/qt/MVGCameraWrapper.hpp"
#include "meshroomMaya/qt/MVGCameraSetWrapper.hpp"
#include <QFocusEvent>
#include <QQuickWidget>
#include <QQmlEngine>
#include <QQmlContext>

namespace meshroomMaya
{

MVGMainWidget::MVGMainWidget(QWidget* parent)
    : QWidget(parent) // <- here
{
    setObjectName("mvgMainWidget");

    qmlRegisterType<MVGCameraWrapper>();
    qmlRegisterType<QObjectListModel>();
    qmlRegisterType<MVGCameraSetWrapper>();

    _view = new QQuickWidget(parent);

    _projectWrapper.loadExistingProject();
    QString importDirectory = QString(MVGMayaUtil::getModulePath().asChar()) + "/qml";

    // QtDesktop Components
    _view->engine()->addPluginPath(importDirectory);
    _view->engine()->addImportPath(importDirectory);

    // Expose Project to QML
    _view->rootContext()->setContextProperty("_project", &_projectWrapper);

    // Qml source
    const char* instantCoding = std::getenv("MESHROOMMAYA_USE_QMLINSTANTCODING");
    QString mainQml = importDirectory + "/mvg/main.qml";
    if(instantCoding)
    {
        QDir qmlFolder = QFileInfo(__FILE__).dir();
        qmlFolder.cd("qml");
        mainQml = QFileInfo(qmlFolder, "main.qml").absoluteFilePath();

        QmlInstantCoding* qic = new QmlInstantCoding(_view, true);
        qic->addFilesFromDirectory(qmlFolder.absolutePath(), true);
    }
    _view->setSource(QUrl::fromLocalFile(mainQml));
    _view->setResizeMode(QQuickWidget::SizeRootObjectToView);
}

MVGMainWidget::~MVGMainWidget()
{
    _projectWrapper.clearAndUnloadImageCache();
}

void MVGMainWidget::focusOutEvent(QFocusEvent* event)
{
    event->accept();
    _view->clearFocus();
}

QWidget* MVGMainWidget::getView() const
{
    return _view;
}

} // namespace

The error is at line 16. Could someone help me with that? What is the problem?


Specs:


I've tried to compile the plug-in with Mayas verison of Qt as well, but when I set the cmake config up in cmake-gui I'm getting problems:

The vcpkg installation of Qt has everything. Shouldn't the devkit contain all I need? Do I have to disable the referencing of the debug binaries somehow?

fabiencastan commented 4 years ago

If I remember correctly, you need to merge the install of Maya and the devkit to get it correctly detected.

fabiencastan commented 4 years ago

I have not yet tested it with Maya-2020.

akuzminykh commented 4 years ago

It would be great if someone would check it with Maya 2020. I've just tried to use the custom Qt stuff (includes, libs) from Maya only and it's still not working. I've spent the last 3 weeks getting this plug-in to run. I'm done. I'm just done ..