Results 1 to 8 of 8

Thread: Building classes with the same name under different namespaces

  1. #1
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Building classes with the same name under different namespaces

    Hello.

    I've got a problem building application that contains 2 classes with the same name under different namespaces.
    AFAIK this situation is legal for C++ classes. However I was not able to build this application with qmake (Qt 4.6.2) because it creates derived files for those classes in the same directory.
    I.e.
    1. object files (Foo.o)
    2. moc files (moc_Foo.cpp)
    3. uic generated files (ui_Foo.h)

    As these files for both classes are generated in the same directory they override one another and the build fails.

    Is there a solution for this problem? (Except avoiding duplicate class names)

    Thanks.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Building classes with the same name under different namespaces

    I thought the output files were based on the filenames, not the class names.

  3. #3
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Building classes with the same name under different namespaces

    Yes.
    And the source filenames are the same as classs name (Foo.h, Foo.cpp, Foo.ui). They are located in a different directories named after the namespaces.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Building classes with the same name under different namespaces

    I think FJM's point was that your file names don't have to be the class name. Try changing one set to anotherfoo.h etc.

  5. The following user says thank you to norobro for this useful post:

    e79ene (6th May 2010)

  6. #5
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Building classes with the same name under different namespaces

    Thanks for suggestion.
    Yes. Changing file names make the build pass.

    However this doesn't look like a complete solution.
    I meen that it seems natural when file name is the same as class name. Moreover this is the way how Qt Creator gives names to the source files.

    I expect the build system to avoid file name conflicts by placing generated files in the directory structure similar to source files location. But I guess it's impossible with qmake. : (

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Building classes with the same name under different namespaces

    I believe it is possible by editing the .pro file yourself, but it's far easier to let Qt Creator do it for you. For example, why not have the filename more like <namespace>_<classname>.cpp/.h ?

  8. The following user says thank you to squidge for this useful post:

    e79ene (6th May 2010)

  9. #7
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Building classes with the same name under different namespaces

    I got your point.
    Thanks.

  10. #8
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Building classes with the same name under different namespaces

    It depends on how you build your application. If you put your files in a directory structure that matches your namespace hierarchy, lets say you have two classes: a::c and b::c, and you put them in a/c.h ab b/c.h, then you cannot use them from the same .pro-file. However, you can create a .pro-file for each directory that is creating a static library and then link you binary against both of them.
    It's nice to be important but it's more important to be nice.

  11. The following user says thank you to axeljaeger for this useful post:

    e79ene (6th May 2010)

Similar Threads

  1. Q_DECLARE_INTERFACE and namespaces
    By JPNaude in forum Qt Programming
    Replies: 2
    Last Post: 5th April 2011, 16:39
  2. ui headers and namespaces
    By Rockem in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2009, 19:47
  3. XML Namespaces
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2008, 10:00
  4. namespaces and translations
    By gri in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2007, 10:53
  5. problem with namespaces
    By steve918 in forum General Programming
    Replies: 1
    Last Post: 17th September 2006, 17:55

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.