Results 1 to 3 of 3

Thread: Files are dropped from SOURCES list

  1. #1
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Files are dropped from SOURCES list

    Hi,

    I have a library project where some classes for legacy reasons have to exist twice, once global and once in a namespace.
    Now I'm trying to migrate this project to qmake but the qmake generated Makefile is missing rules for half of the source files.

    My project consists of files like class.cpp, containing the implementation of the class, and ns_class.cpp looking like
    Qt Code:
    1. namespace mynamespace {
    2.  
    3. #include "class.cpp"
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    My .pro file contains
    Qt Code:
    1. SOURCES += class.cpp ns_class.cpp
    To copy to clipboard, switch view to plain text mode 
    but the generated Makefile only has rules for ns_class.o, depending on ns_class.cpp and class.cpp. Dependy tracking or something seems to filter out the class.o/class.cpp rules.

    Have I missed something obvious? What can I do to make qmake regard the class.cpp as independent source file?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Files are dropped from SOURCES list

    Qt Code:
    1. namespace mynamespace {
    2.  
    3. #include "class.cpp"
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 
    As a first thought, this may not be a good solution, as any standard header files included inside class.cpp will now be defined under mynamesapce, which will lead to lot of mess.

    If you still want to maintain it for some legacy reasons then
    1. Change the file extension of cpp file to some like an include file (.h or .inc) and then include this file from both class.cpp and ns_class.cpp. That way qmake will give expected output.
    2. You need to take care of the gaurd include macros (if used in the first place)

    Here is an exmaple

    Qt Code:
    1. //legacy.pro
    2. HEADERS += \
    3. legacy_class.h \
    4. ns_legacy_class.h
    5.  
    6. SOURCES += \
    7. main.cpp \
    8. legacy_class.cpp \
    9. ns_legacy_class.cpp
    10.  
    11. OTHER_FILES += \
    12. legacy_class.inc
    13.  
    14. //legacy_class.h
    15. #ifndef LEGACY_CLASS_H
    16. #define LEGACY_CLASS_H
    17.  
    18. class legacy_class
    19. {
    20. public:
    21. legacy_class();
    22. };
    23.  
    24. #endif // LEGACY_CLASS_H
    25.  
    26. //ns_legacy_class.h
    27. #ifndef NS_LEGACY_CLASS_H
    28. #define NS_LEGACY_CLASS_H
    29.  
    30. namespace mynamespace {
    31.  
    32. #ifdef LEGACY_CLASS_H
    33. #undef LEGACY_CLASS_H
    34. #include "legacy_class.h"
    35. #define LEGACY_CLASS_H
    36. #else
    37. #include "legacy_class.h"
    38. #endif
    39. }
    40.  
    41. #endif // NS_LEGACY_CLASS_H
    42.  
    43. //legacy_class.cpp
    44. #include "legacy_class.inc"
    45.  
    46. //main.cpp
    47. #include "legacy_class.h"
    48. #include "ns_legacy_class.h"
    49.  
    50. int main(int, char**)
    51. {
    52. legacy_class A;
    53. mynamespace::legacy_class B;
    54. }
    55.  
    56. //ns_legacy_class.cpp
    57. namespace mynamespace {
    58.  
    59. #ifdef LEGACY_CLASS_H
    60. #undef LEGACY_CLASS_H
    61. #include "legacy_class.inc"
    62. #define LEGACY_CLASS_H
    63. #else
    64. #include "legacy_class.inc"
    65. #endif
    66.  
    67. }
    68.  
    69. //legacy_class.inc
    70. #include "legacy_class.h"
    71.  
    72. legacy_class::legacy_class()
    73. {
    74. ;
    75. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    MichaelSchmidtEsd (10th December 2013)

  4. #3
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Files are dropped from SOURCES list

    Quote Originally Posted by Santosh Reddy View Post
    As a first thought, this may not be a good solution, as any standard header files included inside class.cpp will now be defined under mynamesapce, which will lead to lot of mess.
    Okay, I admit, I've oversimplified the description of my real implementation here. I have taken care of this, but thanks for pointing out.

    Quote Originally Posted by Santosh Reddy View Post
    If you still want to maintain it for some legacy reasons then
    1. Change the file extension of cpp file to some like an include file (.h or .inc) and then include this file from both class.cpp and ns_class.cpp. That way qmake will give expected output.
    2. You need to take care of the gaurd include macros (if used in the first place)
    Thanks a lot. That way it worked.

Similar Threads

  1. List all XML files in a directory
    By ouekah in forum Newbie
    Replies: 4
    Last Post: 30th August 2015, 09:47
  2. Replies: 8
    Last Post: 3rd April 2013, 15:45
  3. List files on ftp server using QNetworkAccessManager
    By blackbubblegum in forum Newbie
    Replies: 2
    Last Post: 20th February 2012, 11:39
  4. how can i list of files to QFileSystemModel?
    By aurora in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2012, 08:28
  5. how to list out all files in a dir and sub dir
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2006, 15:57

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.