Results 1 to 20 of 32

Thread: Processor generated QObject?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Processor generated QObject?

    I want to use the preprocessor to make the generation of a certain type of QObject derived class easier. Namely I want to make a QObject that has a slot with some arbitrary signature that translates a Qt signal into a boost signal (which I can use bind with).

    The class structure is built just fine when I try this, it seems, but the moc output doesn't contain metaObject, qt_metacast, nor qt_metacall.

    How might one go about generating classes capable of being connected to Qt signals with either templates (which I know can't have slots) or the preprocessor? I'm using VS2010 with the Qt plugin.

  2. #2
    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: Processor generated QObject?

    You mean you are using templates? Or how did you implement it?
    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
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processor generated QObject?

    Quote Originally Posted by wysota View Post
    You mean you are using templates?
    Eh? Preprocessor != tempaltes, no?

    Or how did you implement it?
    This no work:
    Qt Code:
    1. #define MAKE_OBJECT \
    2. struct my_object : QObject \
    3. { \
    4. my_object(QObject * p) : QObject(p) {} \
    5. Q_OBJECT \
    6. public slots: \
    7. void do_nothing {} \
    8. };
    9.  
    10. MAKE_OBJECT
    To copy to clipboard, switch view to plain text mode 
    Last edited by nroberts; 30th November 2010 at 23:56.

  4. #4
    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: Processor generated QObject?

    I doubt this will work with moc. Try this:
    Qt Code:
    1. #ifdef MAKE_OBJECT
    2. struct ...
    3. #endif
    To copy to clipboard, switch view to plain text mode 
    and have MAKE_OBJECT defined in your project file.
    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.


  5. #5
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processor generated QObject?

    Quote Originally Posted by wysota View Post
    I doubt this will work with moc. Try this:
    Qt Code:
    1. #ifdef MAKE_OBJECT
    2. struct ...
    3. #endif
    To copy to clipboard, switch view to plain text mode 
    and have MAKE_OBJECT defined in your project file.
    That's not at all the same thing.

  6. #6
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processor generated QObject?

    If anyone comes looking for a solution to this issue I've come up with the start of an answer. I posted in on a different forum: http://stackoverflow.com/questions/4...328105#4328105

    In short, it looks like I'll have to bypass the moc and generate moc output with the preprocessor. It looks possible.

    I sure hope Qt becomes compatible with the preprocessor and/or templates in the future.

  7. #7
    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: Processor generated QObject?

    Quote Originally Posted by nroberts View Post
    That's not at all the same thing.
    Of course it's not. Neither qmake nor moc doesn't run preprocessor so you can't expect any of them to notice there is a Q_OBJECT macro in a class that doesn't exist at the time they are called. The preprocessor is ran only when the main compiler runs but then it's too late to spot that a meta-object is needed for the class. If preprocessor was run with every call to qmake and every call to moc, our compilation times would triple only so that one person could be satisfied. You can have the exact same result without using the C preprocessor so just do it instead of complaining. You can even run the preprocessor yourself prior to the moment when qmake checks for existance of Q_OBJECT macro, just be aware you'll possibly get a file the size of several megabytes because all includes will be inlined.
    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
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processor generated QObject?

    Quote Originally Posted by wysota View Post
    Of course it's not.
    Then your suggesting of it as an answer to my query is beyond ignorant, its purposefully misleading. I was beginning to wonder if that wasn't your true objective here.

    Neither qmake nor moc doesn't run preprocessor so you can't expect any of them to notice there is a Q_OBJECT macro in a class that doesn't exist at the time they are called. The preprocessor is ran only when the main compiler runs but then it's too late to spot that a meta-object is needed for the class. If preprocessor was run with every call to qmake and every call to moc, our compilation times would triple only so that one person could be satisfied. You can have the exact same result without using the C preprocessor so just do it instead of complaining. You can even run the preprocessor yourself prior to the moment when qmake checks for existance of Q_OBJECT macro, just be aware you'll possibly get a file the size of several megabytes because all includes will be inlined.
    This is simply false on many levels. The moc already implements a very small subset of the C++ preprocessor. The moc is described, in every single justification of it out there, as an EXTENSION to the C++ language. However, because it only implements a small subset of not only the preprocessor language but also fails to play well with templates, it actually forces users into a *subset* of the C++ language. This isn't a one user issue, it's a language compatibility issue.

    Using meta-programming to create new types is a very common approach to modern C++ design. Qt kills it in every direction I've attempted to take.

    Of course, my question here was an attempt to receive information I *didn't* know. How can I use modern C++ design methods with Qt? I wasn't asking for some self-important ass monkey to send me off on a bunch of wild goose chases and then claim it's all MY fault. There are features I and many others commonly use in C++ that appear to be impossible to use in conjunction with Qt.

    The correct answer to my problem is apparently that what I want to do is impossible to do. Since you apparently knew this all along it is beyond irresponsible and disrespectful for you to waste my time with non-sequitur and red herring. At the very least you should have remarked that you don't know of a way to make it happen or just stayed away from questions you don't have enough knowledge and experience to adequately answer.

  9. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Processor generated QObject?

    You get better information if you stay polite.

    You can of course create something yourself by doing whatever MOC does by yourself.
    For someone like you, who needs this, this would not be a big problem.

  10. #10
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processor generated QObject?

    Quote Originally Posted by tbscope View Post
    You get better information if you stay polite.

    You can of course create something yourself by doing whatever MOC does by yourself.
    For someone like you, who needs this, this would not be a big problem.
    I'm sorry. I'm afraid I don't understand the point of your answer. Could you please explain it more clearly? Exactly what is the solution/workaround you're recommending?

  11. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Processor generated QObject?

    Well, if MOC doesn't want to handle preprocessor code, then you can do it manually.

  12. #12
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processor generated QObject?

    Quote Originally Posted by tbscope View Post
    Well, if MOC doesn't want to handle preprocessor code, then you can do it manually.
    So, your expert advice to auto-generate classes capable of being connected to Qt signals is to write them manually?

  13. #13
    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: Processor generated QObject?

    Quote Originally Posted by nroberts View Post
    The correct answer to my problem is apparently that what I want to do is impossible to do.
    Hmm....
    Quote Originally Posted by wysota View Post
    I doubt this will work with moc.
    I rest my case.

    As for the rest of the thread: nroberts, please stop trolling around. There are myriads of solutions to your problem. The real problem is that you insist on doing it as part of the main compilation step with the C preproc. I personally implemented something you want, it takes a class description such as:

    Cpp Code:
    1. implicitly shared nullable metatyped class MyClass {
    2. string x;
    3. int y;
    4. sequence<QPoint> points;
    5. };
    To copy to clipboard, switch view to plain text mode 

    and generates on the fly a C++ class with getters, setters and a bunch of other stuff that is later compiled with the rest of the program. This particular example is not meant to be used with moc but the generator can also generate a QAbstractItemModel subclass for the payload class that contains the Q_OBJECT macro and gets processed by moc later on. All is done automatically by properly scripting qmake. The trick is that it is an additional step of the compilation which is something you seem to want to avoid.

    Please carefully read our answers instead of treating them as hostile. Note, we might have ignored your posts at all but instead we have chosen to try to help you and answer them. So please try to appreciate it, otherwise in the end you'll be the one who does not get satisfied with the outcome. You will go, we will stay, others will come in your place.
    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. Port Qt to ARC Processor
    By jim_king_2000 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 19th January 2010, 21:22
  2. Replies: 5
    Last Post: 21st August 2009, 15:10
  3. high processor waste...
    By kernel_panic in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 23:12
  4. QProcess processor affinity
    By ibergmark in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2008, 16:09
  5. Locking all threads to one processor
    By chuckshaw in forum Qt Programming
    Replies: 0
    Last Post: 3rd July 2007, 19: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
  •  
Qt is a trademark of The Qt Company.