PDA

View Full Version : Inheritance and Slots/Signals



LMZ
4th June 2007, 16:33
Hello to all, I have problem with ^^subj^^.


class HttpGetFile: public QObject
{
Q_OBJECT

private:
QHttp http;
QVector<QString> qvStates;
QString qstrUrl;
QString qstrHost;
QString qstrPath;
QByteArray qbyteData;
QBuffer Buffer;

public:
HttpGetFile(QObject *parent = 0);
~HttpGetFile();
///Запуск процесса скачки файла, конец по получению сигнала siDone().
void start( const QString& qstrUrlIn, QIODevice& ioDevice);
//QString qstrData;
private slots:
void slStateChanged ( int iState );
void slDone( bool bDone );
void slDataReadProgress ( int done, int total );
signals:

/** \brief Изменение статуса сокета (как-то так =)).
\param iState статус сокета, соотвественно могут быть:\n
0 - Отключено\n
1 - Поиск хоста\n
2 - Подключаюсь\n
3 - Отправка данных\n
4 - Приём данных\n
5 - Подключен\n
6 - Закрытие подключения
*/
void siStateChanged( const int iState );

/** \brief Завершающий сигнал сокета.
\param bError если тру тогда в iError номер ошибки.
\param iError номер ошибки. Соответственно номера ошибок:\n\n
<b>ошибки QHttp</b>\n
0 - Нет ошибки\n
1 - Неизвестная ошибка\n
2 - Хост не найден\n
3 - Сервер отказал в соединении\n
4 - Сервер закрыл соединение по беспределу\n
5 - Ответ сервера не удалось обработать\n
6 - Не удалось определить длину ответа сервера\n
7 - Запрос был прерван (abort())\n\n
<b>ошибки ParseUrl()</b>\n
8 - Адресс не УРЛ\n
9 - http:// сначало УРЛ не найдено
*/
void siDone( bool bError, const int iError );

/** \brief Комментарии излишни :)
\param done сколько уже скачалось
\param total общий размер файла (может быть 0, если серевер не даёт размер файла(редиска))
*/
void siDataReadProgress ( int done, int total );

/** \brief Сигнал используется в деструкторе (в внешних связях не замечен =))
*/
void siAbort();
public:
bool ParseUrl( const QString& qstrUrlIn, int& iError );
void ThrowError( const int iError );
};

and the second class, that's inherites first:


class MainPlugins: public HttpGetFile
{
public:
void GetXMLPluginsList( const QString& qstrUrl );
void SynchronizeWithLocalPlugins();
private:
void ThrowError(int iError, const QString& qstrError);
private slots:
void slDone1(bool bError, const int iError);
signals:
void siDone1(bool bError, const int iError);
private:
QBuffer qbuffXmlPluginsList;
};


when in any function of second class I try to connect HIS (second class) signal with slot:

QObject::connect(this, SIGNAL(siDone1(bool, const int)), this, SLOT(slDone1(bool, const int)));
all compiles ok, but when I try to run this, I get this:
Object::connect: No such signal HttpGetFile::siDone1(bool,int)

why this try connect to the first (HttpGetFile) slot?
help please.

magland
4th June 2007, 16:43
I think you need the Q_OBJECT macro in the second class.

wysota
4th June 2007, 16:57
I think once you have "i" (like internet) and once you have "l" (like localization) - a spelling mistake.

LMZ
4th June 2007, 18:38
magland, you are right. This is strange thing, because when I wrote:
class MainPlugins: public HttpGetFile, public QObject
{
Q_OBJECT
....
I got errors, but if only how you advice all is ok, thanks!!!

marcel
4th June 2007, 19:30
No, you could have solved this by putting QObject first in the inheritance list.

Regards

jpn
4th June 2007, 19:43
class MainPlugins: public HttpGetFile, public QObject
A side note: HttpGetFile already is a QObject. Multiple inheritance from QObject is not supported.