How do I copy object in Qt?
Posted
by Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2010-04-16T11:29:51Z
Indexed on
2010/04/16
11:33 UTC
Read the original article
Hit count: 363
I'm using Qt and have some real basic problems. I have created my own widget MyTest that have a variable obj. I need to set this variable obj from an object outside of the widget so that the variable is copied not just a pointer to another object. I get an error message and can't figure out how to do this basic stuff. This is the code I'm using:
MyTest.h:
class MyTest : public QWidget
{
Q_OBJECT
public:
void setObj(QObject &inobj);
QObject obj;
....
}
MyTest.cpp:
void MyTest::setObj(QObject &inobj) {
obj = inobj; //HERE I get the error message: "illegal access from 'QObject' to protected/private member 'QObject::operator=(const QObject &)'"
}
main.cpp:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QObject *ob = new QObject();
MyTest w;
w.setObj(*ob);
}
Thanks for your help!
© Stack Overflow or respective owner