December 10, 2011

pratik041 pratik041
Lab Rat
346 posts

how we can access data of one project within other project?

Page  
1

I want to use class of one project in other project.

 Signature 

Pratik Agrawal

23 replies

December 10, 2011

Rahul Das Rahul Das
Robot Herder
362 posts

If you have common classes, you could make the libraries and use it.

“Using data of one project in another” ? i dont understand what are you asking :(

 Signature 

——————————-

    Rahul Das

——————————-

December 10, 2011

sierdzio sierdzio
Area 51 Engineer
2333 posts

Either use libraries as Rahul suggested, or simply include the “old” headers in your new project (in this case, you need to remember to add those files to .pro, too).

 Signature 

(Z(:^

December 10, 2011

Volker Volker
Robot Herder
5428 posts

HEADERS and SOURCES can take full paths. You just need to add them to you other project.

December 11, 2011

pratik041 pratik041
Lab Rat
346 posts
Volker wrote:
HEADERS and SOURCES can take full paths. You just need to add them to you other project.

how can we add them to our projects. Can you give any example?

 Signature 

Pratik Agrawal

December 11, 2011

sierdzio sierdzio
Area 51 Engineer
2333 posts

In .pro:

  1. HEADERS = /path/to/old/headers/oldHeader.h
  2. SOURCES = /path/to/old/sources/oldSource.cpp

In your new cpp header (or source):

  1. #include "/path/to/old/headers/oldHeader.h"

 Signature 

(Z(:^

December 11, 2011

Volker Volker
Robot Herder
5428 posts

@sierdzio

The include may not work, if it includes other headers of the old project too. Better add the path to the INCLUDEPATH variable.

December 11, 2011

sierdzio sierdzio
Area 51 Engineer
2333 posts

Oh yes, correct. Just wrote the first thing that came to my mind.

 Signature 

(Z(:^

December 12, 2011

pratik041 pratik041
Lab Rat
346 posts

sierdzio wrote:
In .pro:
  1. HEADERS = /path/to/old/headers/oldHeader.h
  2. SOURCES = /path/to/old/sources/oldSource.cpp

In your new cpp header (or source):
@
#include “/path/to/old/headers/oldHeader.h”
@

I have tried this. Now i am able to access the other file object but while running the code i am getting error.
“No rule to make target ‘/Documents’, needed by ‘debug/documents.o’ stop. “
Does i have to include any more file or any other thing?

 Signature 

Pratik Agrawal

December 12, 2011

sierdzio sierdzio
Area 51 Engineer
2333 posts

Mate, we can’t guess your setup… you have to investigate yourself, or at least give us more data. This error sometimes pops up when QMake was not rerun (clean the project, run qmake, build again), but most probably the cause is different.

 Signature 

(Z(:^

December 12, 2011

pratik041 pratik041
Lab Rat
346 posts

This is my both project which i am testing

  1. file_testing
  2.    main.cpp
  3. #include <QtGui/QApplication>
  4. #include "mainwindow.h"
  5. #include "Documents and Settings/Pratik Agrawal/Desktop..........test1/mainwindow1.h"
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     QApplication a(argc, argv);
  10.     MainWindow w;
  11.     MainWindow1 w1;
  12.     w1.show();
  13.     w.show();
  14.     return a.exec();
  15. }
  16.  
  17. mainwindow.cpp
  18. #include "mainwindow.h"
  19.  
  20. MainWindow::MainWindow(QWidget *parent)
  21.     : QMainWindow(parent)
  22. {
  23. }
  24.  
  25. mainwindow.h
  26. #ifndef MAINWINDOW_H
  27. #define MAINWINDOW_H
  28.  
  29. #include <QtGui/QMainWindow>
  30.  
  31. class MainWindow : public QMainWindow
  32. {
  33.     Q_OBJECT
  34.  
  35. public:
  36.     MainWindow(QWidget *parent = 0);
  37.     ~MainWindow();
  38. };
  39.  
  40. #endif // MAINWINDOW_H
  41. MainWindow::~MainWindow()
  42. {
  43. }
  44.  
  45. file_testing.pro
  46. #-------------------------------------------------
  47. #
  48. # Project created by QtCreator 2011-12-08T15:07:18
  49. #
  50. #-------------------------------------------------
  51.  
  52. QT       += core gui
  53.  
  54. TARGET = file_testing
  55.  
  56. TEMPLATE = app
  57.  
  58.  
  59. SOURCES += main.cpp\
  60.         mainwindow.cpp
  61.  
  62. HEADERS  += mainwindow.h
  63.  
  64. HEADERS = Documents and Settings/Pratik Agrawal/............../test1/mainwindow1.h
  65. SOURCES = Documents and Settings/Pratik Agraw........../Qt gui prgm/test1/mainwindow1.cpp
  66.  
  67.  
  68. OTHER_FILES += \
  69.     data.txt \
  70.     N.txt
  71.  
  72. RESOURCES += \
  73.     resource.qrc

The project which i want to access
test1

  1. main.cpp
  2. #include <QtGui/QApplication>
  3. #include "mainwindow1.h"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     QApplication a(argc, argv);
  8.     MainWindow1 w;
  9.     w.show();
  10.  
  11.     return a.exec();
  12. }
  13.  
  14. mainwindow1.cpp
  15. #include "mainwindow1.h"
  16.  
  17. MainWindow1::MainWindow1(QWidget *parent)
  18.     : QMainWindow(parent)
  19. {
  20. }
  21.  
  22. MainWindow1::~MainWindow1()
  23. {
  24.  
  25. }
  26.  
  27. mainwindow1.h
  28.  
  29. #ifndef MAINWINDOW1_H
  30. #define MAINWINDOW1_H
  31.  
  32. #include <QtGui/QMainWindow>
  33.  
  34. class MainWindow1 : public QMainWindow
  35. {
  36.     Q_OBJECT
  37.  
  38. public:
  39.     MainWindow1(QWidget *parent = 0);
  40.     ~MainWindow1();
  41. };
  42.  
  43. #endif // MAINWINDOW1_H
  44.  
  45. test1.pro
  46. #-------------------------------------------------
  47. #
  48. # Project created by QtCreator 2011-12-12T09:55:33
  49. #
  50. #-------------------------------------------------
  51.  
  52. QT       += core gui
  53.  
  54. TARGET = test1
  55. TEMPLATE = app
  56.  
  57.  
  58. SOURCES += main.cpp\
  59.         mainwindow1.cpp
  60.  
  61. HEADERS  += mainwindow1.h

 Signature 

Pratik Agrawal

December 12, 2011

sierdzio sierdzio
Area 51 Engineer
2333 posts

You’ve got spaces in your paths (file_testing.pro). That is why qmake understands “Documents” as a file. I don’t remember what a remedy for that was in qmake. Try either to enclose the whole path in quotes, or insert ‘\’ in front of every space (probably won’t work, as ‘\’ is used in a different manner in qmake).

Apart from that, I am not sure you can use 2 QMainWindows in a single app (I’ve never tried to, though. And I can’t find anything against it in QMW documentation, so maybe it’s OK).

 Signature 

(Z(:^

December 12, 2011

Rahul Das Rahul Das
Robot Herder
362 posts

  1.     w1.show();
  2.     w.show();

This will work.Two different windows will turn up but ‘w’ will be on top of ‘w1’ and so w1will be hidden.

Why don’t you consider to make one ,the child of other?

 Signature 

——————————-

    Rahul Das

——————————-

December 12, 2011

pratik041 pratik041
Lab Rat
346 posts

sierdzio wrote:
You’ve got spaces in your paths (file_testing.pro). That is why qmake understands “Documents” as a file. I don’t remember what a remedy for that was in qmake. Try either to enclose the whole path in quotes, or insert ‘\’ in front of every space (probably won’t work, as ‘\’ is used in a different manner in qmake).

Apart from that, I am not sure you can use 2 QMainWindows in a single app (I’ve never tried to, though. And I can’t find anything against it in QMW documentation, so maybe it’s OK).

I have used two QMainWindow before also. Their is no problem in using that. As you have suggested
i have checked using double quotes but in that case also it is showing error that

  1. No rule to make target 'path/mainwindow1.cpp' needed by 'debug/mainwindow1.o' . Stop.

I have checked removing spaces between the path also but i am getting the same error.

 Signature 

Pratik Agrawal

December 12, 2011

sierdzio sierdzio
Area 51 Engineer
2333 posts

OK noticed another issue. In your code, you have this (shortened a bit for convenience):

  1. SOURCES += main.cpp\
  2.         mainwindow.cpp
  3.  
  4. HEADERS  += mainwindow.h
  5.  
  6. HEADERS = test1/mainwindow1.h
  7. SOURCES = test1/mainwindow1.cpp

The second invoke of HEADERS and SOURCES is followed by ‘=’, which means it will overwrite previous entries. Try this instead (remember to use your own paths):

  1. SOURCES += main.cpp \
  2.         mainwindow.cpp \
  3.         test1/mainwindow1.cpp
  4.  
  5. HEADERS  += mainwindow.h \
  6.         test1/mainwindow1.h

 Signature 

(Z(:^

December 12, 2011

pratik041 pratik041
Lab Rat
346 posts

sierdzio wrote:
OK noticed another issue. In your code, you have this (shortened a bit for convenience):
  1. SOURCES += main.cpp\
  2.         mainwindow.cpp
  3.  
  4. HEADERS  += mainwindow.h
  5.  
  6. HEADERS = test1/mainwindow1.h
  7. SOURCES = test1/mainwindow1.cpp

The second invoke of HEADERS and SOURCES is followed by ‘=’, which means it will overwrite previous entries. Try this instead (remember to use your own paths):
@
SOURCES += main.cpp \ mainwindow.cpp \ test1/mainwindow1.cpp

HEADERS += mainwindow.h \ test1/mainwindow1.h
@


On changing this i am getting undeclared error.

 Signature 

Pratik Agrawal

Page  
1

  ‹‹ QtOpenCLGL fails in Qt 4.8      [SOLVED] how to reset the combobox to its default state? ››

You must log in to post a reply. Not a member yet? Register here!