Results 1 to 20 of 36

Thread: Minimum required to emit a signal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Minimum required to emit a signal

    I've been using signals and slots with classes derived from classes created in Qt Designer. In addition to inheriting from the class created with Designer, I inherit from QDialog or QWidget (monkey see monkey do).

    I dutifully add the Q_OBJECT in the derived class header file, and everything seems work. I can connect signals of built-in widgets to my own custom slots and emit (and connect) my own custom signals. I must confess I don't understand what's going on "under the covers".

    I have some utility classes that really aren't GUI oriented. But, I can see it would be handy for some of the methods in these clases to emit signals that could be connected to new widgets I'd create for displaying some diagnostic information.

    I think I need the Q_OBJECT in these class declarations to have a signals: keyword

    But, what what do should I inherit from? When I tried to public inherit only from QDialog or QWidget, the compiler complains about not being able to access private data in the base class. And that doesn't seem clean, given my derived class is only similar to a QDialog or QWidget in that it would emit a signal.

    So, what do I need just to create a signal?

    Thanks,

    Dave Thomas

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

    Default Re: Minimum required to emit a signal

    Quote Originally Posted by davethomaspilot View Post
    But, what what do should I inherit from?
    Inherit QObject.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Minimum required to emit a signal

    Thanks for the quick reply.

    I get similar error messages when inheriting from QObject:

    1>c:\users\dave\my software\stats helper\heat_message.h(127): error C2248: 'QObject:perator =' : cannot access private member declared in class 'QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(333) : see declaration of 'QObject:perator ='
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(112) : see declaration of 'QObject'
    1> This diagnostic occurred in the compiler generated function 'HeatMessage &HeatMessage:perator =(const HeatMessage &)'
    1> main_window.cpp

    1>c:\users\dave\my software\stats helper\heat_message.h(127): error C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(333) : see declaration of 'QObject::QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(112) : see declaration of 'QObject'
    1> This diagnostic occurred in the compiler generated function 'HeatMessage::HeatMessage(const HeatMessage &)'
    1> moc_collect_stats.cpp
    1>c:\users\dave\my software\stats helper\heat_message.h(127): error C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(333) : see declaration of 'QObject::QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(112) : see declaration of 'QObject'
    1> This diagnostic occurred in the compiler generated function 'HeatMessage::HeatMessage(const HeatMessage &)'
    1> moc_main_window.cpp
    1>c:\users\dave\my software\stats helper\heat_message.h(127): error C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(333) : see declaration of 'QObject::QObject'
    1> c:\opencv\dep\qt\qt-everywhere-opensource-src-4.8.2\include\qtcore\../../src/corelib/kernel/qobject.h(112) : see declaration of 'QObject'
    1> This diagnostic occurred in the compiler generated function 'HeatMessage::HeatMessage(const HeatMessage &)'
    1> Generating Code...
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:07.10

    It compiles fine without the Q_OBJECT and inheritance from QObject.

    Do I need a different constructor that passes 0 to the Bo

    Here's the relevant part of header file:
    Qt Code:
    1. #ifndef HEAT_MESSAGE_H
    2. #define HEAT_MESSAGE_H
    3.  
    4. #include <QtCore/QCoreApplication>
    5. #include <QRegExp>
    6. #include <QMap>
    7. #include <iostream>
    8. #include <fstream>
    9. #include <QTextStream>
    10. #include <QWidget>
    11.  
    12. class HeatMessage : public QObject
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. HeatMessage(QByteArray &,QObject *parent=0);
    18. HeatMessage(void);
    19. QList<HeatRecord> heat_records;
    20. float get_time(char lane, char id);
    21. float get_sum_time(char lane);
    22. char get_result(char lane);
    23. int get_race(void) {return heat_records.begin()->get_race();};
    24. int get_heat(void) {return heat_records.begin()->get_heat();};
    25. int num_dogs(char lane);
    26. static void print_header(QTextStream &);
    27. void print(char lane, QTextStream &);
    28. void print(QTextStream &);
    To copy to clipboard, switch view to plain text mode 



    };
    #endif

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Minimum required to emit a signal

    The QObject copy and assignment constructors are declared private. You cannot copy a QObject and will get these sort of errors if you attempt to do that.

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

    Default Re: Minimum required to emit a signal

    You can't create copies or assignments to QObject instances. You probably have an assignment operator in your class (or the compiler tries to create one for you based on your code). This is not possible.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Minimum required to emit a signal

    Hmm, I don't see anthing like that, unless the following fragment (which is called from a method in a different QWidget class)

    Qt Code:
    1. HeatMessage hm(msg);
    2. emit new_heat(hm);
    To copy to clipboard, switch view to plain text mode 

    Do you have a suggestion on how to find the offending code?

    Thanks,

    Dave Thomas

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

    Default Re: Minimum required to emit a signal

    What is in heat_message.h file in line 127 (and around)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Minimum required to emit a signal

    That's the last line in the header file (the }

    Not very useful.

    [code]

    void print(char lane, QTextStream &);
    void print(QTextStream &);



    line 127: };

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

    Default Re: Minimum required to emit a signal

    Please post the whole file as an attachment.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Emit signal outside run() in QThread
    By naturalpsychic in forum Qt Programming
    Replies: 4
    Last Post: 26th March 2012, 16:31
  2. How to decide which SIGNAL to emit?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2011, 15:09
  3. Replies: 2
    Last Post: 3rd May 2011, 20:22
  4. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 14:26
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 11:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.