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. [SOLVED]having trouble including a file

[SOLVED]having trouble including a file

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 3.9k Views 2 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.
  • M Offline
    M Offline
    manny
    wrote on last edited by manny
    #1

    hello,

    I am a beginner in qt programming, and stumbled across the following problem.

    I have this project in which i needed to include some files from other projects however when I tried including a certain file the compiler flagged it as an error. This file belonged to a previous project, and was added to the current project by right clicking on the project tree and clicking on "add existing files". additionally, when I added another file from a different project (both located in the same directory though), it was able to be included on the project just fine. Additionally, when I checked to see if the file (the one that is having trouble being included), is not in my current project directory. does anyone know what may be wrong? perhaps the compiler does not know where to look for the file (even though it found the other one) . all these files are header files.

    any help is greatly appreciated

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      the compiler flagged it as an error

      What compiler?
      Which IDE?
      What did the error say?
      What are the paths to your project and the include file in question?
      What did you try already?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        manny
        wrote on last edited by manny
        #3

        compiler: MSVC 2013 64bit

        ide: qt creator 2015

        error: no such file or directory found

        path : C:\Users\MyName\Documents\qtDesighn

        tried searching for solutions online, and putting folder in different paths

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Does the error also say the path to the file it can't find?

          Can you paste the full path (including file name) of the include file, the path to where your .pro file is located and content of the HEADERS += section in your .pro file?

          Btw. Qt Creator is not versioned with years as new versions come out a couple of times in any given year, so there's no Qt Creator 2015. Current version is 3.5.0 (see Help->About).

          1 Reply Last reply
          1
          • M Offline
            M Offline
            manny
            wrote on last edited by manny
            #5

            sorry, thanks for the reply

            these are the contents of my HEADERS += file

                HEADER +=  mainwindow.h \
            finddialog.h \
            sortdialog.h \
            spreadsheet.h \
            ../../hideDialog/sortdialog.h \
            ../../qtdesighn/cells.h \
            gotocelldialog.h
            

            it is cells.h that is having trouble being included

            1 Reply Last reply
            0
            • M Offline
              M Offline
              manny
              wrote on last edited by manny
              #6

              the full path of cells.h is file:///C:/Users/myName/Documents/qtDesighn/cells.h

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #7

                The paths here are relative to the location of the .pro file. As it is now it is 2 directories up and then qtdesighn directory.
                This is correct if your .pro file is located in C:/Users/myName/Documents/<something>/<something>/yourprofile.pro.
                If that is not the case then you need to adjust the path in the HEADERS section.

                Oh, an for the record. This makes this file part of your project. If you only want to include it without making it part of the project you should remove it from HEADERS variable and instead specify a path to directory it is placed in in the INCLUDEPATH variable.

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  manny
                  wrote on last edited by
                  #8

                  I want the file to be part of the project, so i guess i will try to change the file path in the HEADERS section of the .pro file

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    manny
                    wrote on last edited by manny
                    #9

                    sorry, but i tried changing the HEADER section of the .pro file as such

                        HEADERS  += mainwindow.h \
                    finddialog.h \
                    sortdialog.h \
                    spreadsheet.h \
                    gotocelldialog.h \
                    ../../C++/mainWindow/cells.h                      
                    

                    C++/mainWindow/cells.h is the exact same directory that the .pro file is located in.

                    however cells.h is still not being included. and also, cells.h is not showing up in the directory of the project even after i added it to the project.

                    1 Reply Last reply
                    0
                    • Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by Chris Kawa
                      #10

                      That makes no sense. You said the cells.h file was located in C:/Users/myName/Documents/qtDesighn. If so then of course adding ../../C++/mainWindow/cells.h to the HEADERS won't work as there is no such file in that directory.

                      As I said the paths in HEADERS are relative to the location of the .pro file. .. means "1 directory up".
                      You didn't post the path to the .pro file, so I'm gonna make up a couple of examples so that you can see how that works.

                      C:/some_directory/some_project/some_header.h
                      C:/some_directory/some_project/project.pro
                      HEADERS += some_header.h

                      C:/some_directory/some_project/include/some_header.h
                      C:/some_directory/some_project/project.pro
                      HEADERS += include/some_header.h

                      C:/some_directory/some_library/include/some_header.h
                      C:/some_directory/some_project/project.pro
                      HEADERS += ../some_library/include/some_header.h

                      C:/some_directory/some_library/include/some_header.h
                      C:/some_directory/some_project/some_subdirectory/project.pro
                      HEADERS += ../../some_library/include/some_header.h

                      I hope you see the pattern. If you post a full path to the .pro file I can tell you what you should put in the HEADERS.

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        manny
                        wrote on last edited by manny
                        #11

                        alright, i made a new project called tests in which my .pro file has the current path:

                            C:\Users\myName\documents\tests\tests.pro
                        

                        the file i am trying to include is:

                            C:\Users\myName\documents\hideDialog\sortdialog.h
                        

                        in my HEADERS section of the .pro file i included sortDialog.h as so:

                           HEADERS += ../hideDialog/sortdialog.h
                        

                        however when i try to include sortdialog.h in main as so:

                             #include "sortdialog.h"
                        

                        the compiler flags it as an error saying "no such file or directory found"

                        1 Reply Last reply
                        0
                        • Chris KawaC Offline
                          Chris KawaC Offline
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          HEADERS += ../hideDialog/sortdialog.h

                          I'm assuming this correctly adds this file to the project and it shows up in the project tree in Creator, right? That's one thing, but...

                          #include "sortdialog.h"

                          Adding a file to project doesn't mean you're automatically adding its directory to the paths that are searched for includes.
                          The above would make the compiler look for the include in the same directory as the file including, which is not the case here.

                          You can do one of these:

                          • specify the correct path in the include statement: #include "../hideDialog/sortdialog.h"
                          • add the directory to searched paths in your .pro file: INCLUDEPATH += ../hideDialog and then you can use #include "sortdialog.h"
                          1 Reply Last reply
                          1
                          • M Offline
                            M Offline
                            manny
                            wrote on last edited by
                            #13

                            so, that was the problem. my bad, and thank you very much for the replies, thanks

                            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