Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how we can access data of one project within other project?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
24 Posts 4 Posters 13.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #3

    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).

    (Z(:^

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #4

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

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #5

        [quote author="Volker" date="1323525174"]HEADERS and SOURCES can take full paths. You just need to add them to you other project.[/quote]

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

        Pratik Agrawal

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #6

          In .pro:
          @
          HEADERS = /path/to/old/headers/oldHeader.h
          SOURCES = /path/to/old/sources/oldSource.cpp
          @

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

          (Z(:^

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #7

            @sierdzio

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

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #8

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

              (Z(:^

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pratik041
                wrote on last edited by
                #9

                [quote author="sierdzio" date="1323599112"]In .pro:
                @
                HEADERS = /path/to/old/headers/oldHeader.h
                SOURCES = /path/to/old/sources/oldSource.cpp
                @

                In your new cpp header (or source):
                @
                #include "/path/to/old/headers/oldHeader.h"
                @[/quote]

                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?

                Pratik Agrawal

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #10

                  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.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pratik041
                    wrote on last edited by
                    #11

                    This is my both project which i am testing
                    @file_testing
                    main.cpp
                    #include <QtGui/QApplication>
                    #include "mainwindow.h"
                    #include "Documents and Settings/Pratik Agrawal/Desktop..........test1/mainwindow1.h"

                    int main(int argc, char *argv[])
                    {
                    QApplication a(argc, argv);
                    MainWindow w;
                    MainWindow1 w1;
                    w1.show();
                    w.show();
                    return a.exec();
                    }

                    mainwindow.cpp
                    #include "mainwindow.h"

                    MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    {
                    }

                    mainwindow.h
                    #ifndef MAINWINDOW_H
                    #define MAINWINDOW_H

                    #include <QtGui/QMainWindow>

                    class MainWindow : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    MainWindow(QWidget *parent = 0);
                    ~MainWindow();
                    };

                    #endif // MAINWINDOW_H
                    MainWindow::~MainWindow()
                    {
                    }

                    file_testing.pro
                    #-------------------------------------------------

                    Project created by QtCreator 2011-12-08T15:07:18

                    #-------------------------------------------------

                    QT += core gui

                    TARGET = file_testing

                    TEMPLATE = app

                    SOURCES += main.cpp
                    mainwindow.cpp

                    HEADERS += mainwindow.h

                    HEADERS = Documents and Settings/Pratik Agrawal/............../test1/mainwindow1.h
                    SOURCES = Documents and Settings/Pratik Agraw........../Qt gui prgm/test1/mainwindow1.cpp

                    OTHER_FILES +=
                    data.txt
                    N.txt

                    RESOURCES +=
                    resource.qrc
                    @

                    The project which i want to access
                    test1
                    @
                    main.cpp
                    #include <QtGui/QApplication>
                    #include "mainwindow1.h"

                    int main(int argc, char *argv[])
                    {
                    QApplication a(argc, argv);
                    MainWindow1 w;
                    w.show();

                    return a.exec&#40;&#41;;
                    

                    }

                    mainwindow1.cpp
                    #include "mainwindow1.h"

                    MainWindow1::MainWindow1(QWidget *parent)
                    : QMainWindow(parent)
                    {
                    }

                    MainWindow1::~MainWindow1()
                    {

                    }

                    mainwindow1.h

                    #ifndef MAINWINDOW1_H
                    #define MAINWINDOW1_H

                    #include <QtGui/QMainWindow>

                    class MainWindow1 : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    MainWindow1(QWidget *parent = 0);
                    ~MainWindow1();
                    };

                    #endif // MAINWINDOW1_H

                    test1.pro
                    #-------------------------------------------------

                    Project created by QtCreator 2011-12-12T09:55:33

                    #-------------------------------------------------

                    QT += core gui

                    TARGET = test1
                    TEMPLATE = app

                    SOURCES += main.cpp
                    mainwindow1.cpp

                    HEADERS += mainwindow1.h
                    @

                    Pratik Agrawal

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #12

                      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).

                      (Z(:^

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Rahul Das
                        wrote on last edited by
                        #13

                        @ w1.show();
                        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?


                        Declaration of (Platform) independence.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pratik041
                          wrote on last edited by
                          #14

                          [quote author="sierdzio" date="1323677232"]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).[/quote]

                          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
                          @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.

                          Pratik Agrawal

                          1 Reply Last reply
                          0
                          • sierdzioS Offline
                            sierdzioS Offline
                            sierdzio
                            Moderators
                            wrote on last edited by
                            #15

                            OK noticed another issue. In your code, you have this (shortened a bit for convenience):
                            @
                            SOURCES += main.cpp
                            mainwindow.cpp

                            HEADERS += mainwindow.h

                            HEADERS = test1/mainwindow1.h
                            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
                            @

                            (Z(:^

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              pratik041
                              wrote on last edited by
                              #16

                              [quote author="sierdzio" date="1323681848"]OK noticed another issue. In your code, you have this (shortened a bit for convenience):
                              @
                              SOURCES += main.cpp
                              mainwindow.cpp

                              HEADERS += mainwindow.h

                              HEADERS = test1/mainwindow1.h
                              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
                              @[/quote]
                              On changing this i am getting undeclared error.

                              Pratik Agrawal

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on last edited by
                                #17

                                Do you use shadow builds with Qt Creator?

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply
                                0
                                • R Offline
                                  R Offline
                                  Rahul Das
                                  wrote on last edited by
                                  #18

                                  The code you gave is working for me, except that i changed
                                  the header in the first project 'file_testing' to
                                  @#ifndef MAINWINDOW_H
                                  #define MAINWINDOW_H

                                  #include <QtGui/QMainWindow>

                                  class MainWindow : public QMainWindow
                                  {
                                  Q_OBJECT

                                  public:
                                  MainWindow(QWidget *parent = 0);
                                  ~MainWindow(){};
                                  };

                                  #endif // MAINWINDOW_H@

                                  I felt, the destructor was improperly positioned ;)


                                  Declaration of (Platform) independence.

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    pratik041
                                    wrote on last edited by
                                    #19

                                    [quote author="Volker" date="1323688757"]Do you use shadow builds with Qt Creator?[/quote]

                                    yes i used shadow build.

                                    Pratik Agrawal

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on last edited by
                                      #20

                                      [quote author="pratik041" date="1323690516"]
                                      [quote author="Volker" date="1323688757"]Do you use shadow builds with Qt Creator?[/quote]

                                      yes i used shadow build.[/quote]

                                      Then I'm not 100% sure whether the approach I suggested does actually work as the directory layout is a bit delicate in that case.

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        pratik041
                                        wrote on last edited by
                                        #21

                                        [quote author="Rahul Das" date="1323690185"]The code you gave is working for me, except that i changed
                                        the header in the first project 'file_testing' to
                                        @#ifndef MAINWINDOW_H
                                        #define MAINWINDOW_H

                                        #include <QtGui/QMainWindow>

                                        class MainWindow : public QMainWindow
                                        {
                                        Q_OBJECT

                                        public:
                                        MainWindow(QWidget *parent = 0);
                                        ~MainWindow(){};
                                        };

                                        #endif // MAINWINDOW_H@

                                        I felt, the destructor was improperly positioned ;)[/quote]

                                        Actually in my code i have used it properly while pasting the destructor is pasted wrongly.
                                        Does you are able to access other project object in your code?

                                        Pratik Agrawal

                                        1 Reply Last reply
                                        0
                                        • R Offline
                                          R Offline
                                          Rahul Das
                                          wrote on last edited by
                                          #22

                                          yes. i compiled and its working. I used the relative path. May be you should also try.


                                          Declaration of (Platform) independence.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved