Ошибка member access into incomplete type qqmlcontext

I’m referencing this doc: http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html but am still missing a crucial step I believe

Basically, I’m making a custom loader using QPaint. I make a class for the custom loader, put all methods in the header and include the paint event in the corresponding cpp file.

CustomLoader::CustomLoader(QQuickItem *parent)
    : QQuickPaintedItem(parent)
{
Q_ASSERT(m_maxValue>=m_minValue); // make sure max is the same or more than the min
    QWidget::paintEvent(event); // call the base class implementation
    QPainter painter(this); // set a painter to paint on the widget
}

void CustomLoader::paint(QPainter *painter){
}

void CustomLoader::setProgress(int progress) //this sets the percentage of completed the loader is 
{

}

I then use the application engine to setContextProperty

CustomLoader customLoader(NULL);

    engine.rootContext()->setContextProperty("customLoader", customLoader);
    customLoader.setProgress(50);

And get the following error:

main.cpp:15: error: member access into incomplete type 'QQmlContext'
    engine.rootContext()->setContextProperty("customLoader", customLoader);
                        

my CustomLoader.qml is simply this:

import QtQuick 2.0

Item {
    width: 300
    height: 300

}

I am very new to this and thus have a few questions.
1.) Any ideas what is causing the error I am receiving about accessing an incomplete type?
2.) How do I pass the CustomLoader paint object to the CustomLoader QML so that it displays in the QML element?

Thank you!

Example from Qt’s documention will not compile (on exposing a C++ method to QML)

EDIT I was basically able to get this to work, thanks in large part to u/doctorfill456. However, in looking up how to do the next thing, I actually found a much easier way. It’s long enough that I’m going to make a separate post, which is here.

Original post follows:

This is driving me absoultely up the wall. I’ve been trying to piece together different parts of the documentation on this (because it never actually shows you the full thing, and keeps changing other parts when it shows you the next step).

So I’m trying to have a C++ class that can return a value that QML can then load.

Here’s the relevant bits of my C++ class:

class TextProcessor : public QObject {

    Q_OBJECT
    Q_PROPERTY(QString literalText READ literalText WRITE writeLiteralText NOTIFY literalTextChanged)

    public:
        
        /* snip */

        QString literalText() const {

            return tempString;

        }

    private:

        QString tempString = "blah";

}

Then in main.cpp:

int main(int argc, char *argv[]) {

    QGuiApplication app(argc, argv);

    TextProcessor textProcessor;
    QQuickView view;

    view.engine()->rootContext()->setContextProperty("textProcessor", &textProcessor);   // THIS LINE BREAKS
    view.setSource(QUrl::fromLocalFile("main.qml"));
    view.show();

    return app.exec();

}

The documentation says this method should allow calling various methods of the class from within QML. However, the line I mentioned above breaks on trying to envoke setContextProperty(), with this error: member access into incomplete type 'QQmlContext'. This approach is word-for-word out of Qt’s documentation, and yet.

I had originally not been using a QQuickView at all. Instead doing an instance of QQmlApplicationEngine for loading the QML file, and using qmlRegisterType. This compiles, but nothing from the C++ class is accessible from the QML file (Unable to assign [undefined] to QString).

I assume I’m missing something obvious, but I am completely at a loss for what.

I have two classes in the same .cpp file:

// forward
class B;

class A {       
   void doSomething(B * b) {
      b->add();
   }
};

class B {
   void add() {
      ...
   }
};

The forward does not work, I cannot compile.

I get this error:

error: member access into incomplete type 'B'
note: forward declaration of 'B'

I’m using clang compiler (clang-500.2.79).

I don’t want to use multiple files (.cpp and .hh), I’d like to code just on one .cpp.

I cannot write the class B before the class A.

Do you have any idea of how to resolve my problem ?


Christopher

Hi I just started using felgo and I need to use c++ with it. I’m following the tutorial on c++ integration but I’m running into trouble. I’m following here but when I get to Expose an Object to QML as a Context Property I get this error at engine.rootContext()->setContextProperty:

main.cpp:34:25: error: member access into incomplete type ‘QQmlContext’
qqml.h:570:7: note: forward declaration of ‘QQmlContext’

I can get to engine.rootContext() but setContextProperty doesn’t seem to exist.

Any help and/or advice?


Filippo

Hi Christopher,

thank you for reaching out to us. Is it possible that you’re missing the include for QQmlContext in your main.cpp file:

#include <QQmlContext>

Feel free to let me know if that fixes your issues or if you need help with something else.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Pick a username
Email Address
Password

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

  • Ошибка mdp форсунки rexton
  • Ошибка mfc140u dll что делать
  • Ошибка md5 при прошивке
  • Ошибка mcvcr120 dll что делать
  • Ошибка mcvcr120 dll ведьмак 3