Results 1 to 6 of 6

Thread: Inheritance and Slots/Signals

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    46
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Inheritance and Slots/Signals

    Hello to all, I have problem with ^^subj^^.
    Qt Code:
    1. class HttpGetFile: public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. private:
    6. QHttp http;
    7. QVector<QString> qvStates;
    8. QString qstrUrl;
    9. QString qstrHost;
    10. QString qstrPath;
    11. QByteArray qbyteData;
    12. QBuffer Buffer;
    13.  
    14. public:
    15. HttpGetFile(QObject *parent = 0);
    16. ~HttpGetFile();
    17. ///Запуск процесса скачки файла, конец по получению сигнала siDone().
    18. void start( const QString& qstrUrlIn, QIODevice& ioDevice);
    19. //QString qstrData;
    20. private slots:
    21. void slStateChanged ( int iState );
    22. void slDone( bool bDone );
    23. void slDataReadProgress ( int done, int total );
    24. signals:
    25.  
    26. /** \brief Изменение статуса сокета (как-то так =)).
    27. \param iState статус сокета, соотвественно могут быть:\n
    28. 0 - Отключено\n
    29. 1 - Поиск хоста\n
    30. 2 - Подключаюсь\n
    31. 3 - Отправка данных\n
    32. 4 - Приём данных\n
    33. 5 - Подключен\n
    34. 6 - Закрытие подключения
    35. */
    36. void siStateChanged( const int iState );
    37.  
    38. /** \brief Завершающий сигнал сокета.
    39. \param bError если тру тогда в iError номер ошибки.
    40. \param iError номер ошибки. Соответственно номера ошибок:\n\n
    41. <b>ошибки QHttp</b>\n
    42. 0 - Нет ошибки\n
    43. 1 - Неизвестная ошибка\n
    44. 2 - Хост не найден\n
    45. 3 - Сервер отказал в соединении\n
    46. 4 - Сервер закрыл соединение по беспределу\n
    47. 5 - Ответ сервера не удалось обработать\n
    48. 6 - Не удалось определить длину ответа сервера\n
    49. 7 - Запрос был прерван (abort())\n\n
    50. <b>ошибки ParseUrl()</b>\n
    51. 8 - Адресс не УРЛ\n
    52. 9 - http:// сначало УРЛ не найдено
    53. */
    54. void siDone( bool bError, const int iError );
    55.  
    56. /** \brief Комментарии излишни :)
    57. \param done сколько уже скачалось
    58. \param total общий размер файла (может быть 0, если серевер не даёт размер файла(редиска))
    59. */
    60. void siDataReadProgress ( int done, int total );
    61.  
    62. /** \brief Сигнал используется в деструкторе (в внешних связях не замечен =))
    63. */
    64. void siAbort();
    65. public:
    66. bool ParseUrl( const QString& qstrUrlIn, int& iError );
    67. void ThrowError( const int iError );
    68. };
    To copy to clipboard, switch view to plain text mode 
    and the second class, that's inherites first:
    Qt Code:
    1. class MainPlugins: public HttpGetFile
    2. {
    3. public:
    4. void GetXMLPluginsList( const QString& qstrUrl );
    5. void SynchronizeWithLocalPlugins();
    6. private:
    7. void ThrowError(int iError, const QString& qstrError);
    8. private slots:
    9. void slDone1(bool bError, const int iError);
    10. signals:
    11. void siDone1(bool bError, const int iError);
    12. private:
    13. QBuffer qbuffXmlPluginsList;
    14. };
    To copy to clipboard, switch view to plain text mode 

    when in any function of second class I try to connect HIS (second class) signal with slot:
    Qt Code:
    1. QObject::connect(this, SIGNAL(siDone1(bool, const int)), this, SLOT(slDone1(bool, const int)));
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inheritance and Slots/Signals

    I think you need the Q_OBJECT macro in the second class.

  3. The following user says thank you to magland for this useful post:

    LMZ (4th June 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Inheritance and Slots/Signals

    I think once you have "i" (like internet) and once you have "l" (like localization) - a spelling mistake.

  5. #4
    Join Date
    May 2007
    Posts
    46
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inheritance and Slots/Signals

    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!!!

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inheritance and Slots/Signals

    No, you could have solved this by putting QObject first in the inheritance list.

    Regards

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Inheritance and Slots/Signals

    Quote Originally Posted by LMZ View Post
    class MainPlugins: public HttpGetFile, public QObject
    A side note: HttpGetFile already is a QObject. Multiple inheritance from QObject is not supported.
    J-P Nurmi

Similar Threads

  1. Connecting slots/signals in subclassed form
    By qball2k5 in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 16:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.