Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Processor generated QObject?

  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,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: 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,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: 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,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: 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
    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?

    Are you aware that a preprocessor and MOC are written manually?
    You can write your own preprocessor or script to handle the files before they are compiled.

  14. #14
    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
    Are you aware that a preprocessor and MOC are written manually?
    You can write your own preprocessor or script to handle the files before they are compiled.
    Oh, IC. Your expert answer to a question in the newbie section asking how to auto-generate Qt classes is to rewrite the MOC.

    Sounds reasonable.

  15. #15
    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?

    Please don't be so hostile. I just want to help you.

    And yes, if you want something as specific as you want, and it doesn't exist, the only thing you can do is create it yourself.

    Basically, that's what you already got above.

    Your question does not belong in the newbie or even advanced section. You question belongs in a "super geeky nerd" section.

    Look at it from the other side.
    What I think you have done is made some poor choices along the line.

    Can you explain exactly what you want to do in clear and plain text. Don't use the following words: preprocessor, templates, moc
    And be verbose.

  16. #16
    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
    Please don't be so hostile. I just want to help you.
    This is obviously false.

    And yes, if you want something as specific as you want, and it doesn't exist, the only thing you can do is create it yourself.
    I think you might have just beat the other poster in this thread for most ridiculous response ever, though it is pretty hard to compete with using ifdef to autogenerate classes. Not only is it completely redundant to say, "If it doesn't exist then make it," it is also quite possibly the very wrong thing to do, especially if the cost to make it is higher than worth. Several other options come to mind: live without it, don't use Qt, etc... All of which are quite redundant and beside the point of the real question though and amount to no more than simple efforts to be obnoxious.

    Your question does not belong in the newbie or even advanced section. You question belongs in a "super geeky nerd" section.
    BULL. The question is simple: how do you use the preprocessor or templates to generate Qt objects.

    The answer is also quite simple and still I'm the only one in this entire thread that even mentioned it: you can't. The rest of your guys' nonsense is just that.

    What I think you have done is made some poor choices along the line.
    Which is simply an amazing presentation of mind-reading abilities.

    Can you explain exactly what you want to do in clear and plain text. Don't use the following words: preprocessor, templates, moc
    And be verbose.
    The question is, and has always been, quite clear in my first post and I answered it myself (in spite of attempts to send me down blind alleys) quite a long time ago; even to the point of including exactly the problem I'm trying to solve.

  17. #17
    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?

    What I mean with helping you is to get to the point to have something that you want.
    You're fixed on the preprocessor. Maybe there's another way to do what you want.
    But to know this, I need to know exactly what you want, and that's still not clear for me.

    By the way, there's a Qt mailing list where you can ask the Qt developers directly for support.
    http://lists.qt.nokia.com/mailman/listinfo/qt-interest

  18. #18
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Processor generated QObject?

    I can't decipher what it is you're trying to accomplish, but the C/C++ preprocessor is almost trivially simple; you can learn all there is to know about it in a couple of hours. If you can't figure out how to accomplish something using it, you either have to A) devote a small amount of time to learning how it works, or B) recognize that the preprocessor is almost certainly the wrong tool, and look for another solution.

    For starters, perhaps you should also devote some time to A) being polite, and B) providing a reasonably detailed explanation of what the problem is you're trying to solve. Without more information, it's really impossible to suggest any reasonable solution other than to mention that there are many potential tools available for generating code - lex, yacc, perl, python and dozens of others, not to mention C++ and maybe - just maybe - the preprocessor.

  19. #19
    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 SixDegrees View Post
    I can't decipher what it is you're trying to accomplish, but the C/C++ preprocessor is almost trivially simple; you can learn all there is to know about it in a couple of hours. If you can't figure out how to accomplish something using it, you either have to A) devote a small amount of time to learning how it works, or B) recognize that the preprocessor is almost certainly the wrong tool, and look for another solution.
    The preprocessor is absolutely the right tool for the job and is fully capable of doing exactly what I want. The problem stems from having to use the MOC and its inability to play well with the preprocessor and with templates.

    I think the real problem here is that "Newbie" on this forum isn't a place for new Qt users to get help from expert users, but where those answering are also newbies. Even the moderator seems particularly so. Nothing wrong with being a newbie but it is particularly frustrating to ask for help expecting knowledgeable people and running into a bunch of yahoo's claiming to be experts but spout nonsense. In other words, I come here as a complete newb to Qt and have found that the "experts" know less than I do at apparently every level. My bad for coming to the wrong place I suppose, but in my defense it is one of the support links on the Qt site proper.

    That said, I'm pretty tired of people "answering" my question just to claim I'm being a) impolite or b) not specific enough. The question is quite clear and has actually been answered already. Anyone else doing so is just going to end up on my ignore list, and if you're here to actually get help....I am an expert; I just happen to be new to Qt. I also don't waste your time with my own ignorance. If you actually have something pertinent to my question that hasn't been brought up then I'm all for hearing it, but I'm tired of people just posting to flame.

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