Here is my sample code:
class hoho : public QObject { Q_OBJECT public: hoho() { httpFetch = new HttpFetch(QUrl("http://www.google.com/")); connect(httpFetch, SIGNAL(Fetched()), this, SLOT(PrintData(QByteArray))); } void PrintData(QByteArray http) { qDebug()<<http; } HttpFetch *httpFetch; };
When I try to compile this, following error pops up
1>main.cpp(15): error C2243: 'type cast' : conversion from 'HttpFetch *' to 'const QObject *' exists, but is inaccessible
This error comes as the class is derived from QObject
(which is necessary for signal and slot mechanism).
Can anyone tell me how to fix this?
You probably did not derive HttpFetch
publicly, but privately from QObject
. So just change
class HttpFetch : QObject { // ...
to
class HttpFetch : public QObject { // ...
and it should work.
If your design requires to make the inheritance non-public (I had this requirement because I inherited from a QWidget
for a multithreading purpose and didn't want to expose all functions to the user), you can do this:
class FilesQueueQList : protected QWidget { Q_OBJECT public: using QWidget::QObject; //This is the solution! //... }
Now the members of QWidget are private/protected, but QObject is accessible as public.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With