Code: Select all
// main.cpp
#include
#include
int main(int argc, char* argv[])
{
QtClass q;
q.foo();
emit q.bar();
}
Code: Select all
// qtclass.h
#include
class QtClass : public QObject
{
Q_OBJECT
public:
void foo()
{
QString msg = "Hello";
QObject::connect(this, &QtClass::bar, this, [&msg]()
{
msg.append(" World"); // access violation reading position, msg is out of scope
});
};
signals:
void bar();
};
Mobile version