Cannot open include file error
I'm a new Qt user and I've encountered a problem of using custom widget. Here is the description. Can anyone please help me out?
I'm using VS2013 with Qt5 Addin.
I created a MyOpenGLWidget inherits QOpenGLWidget in a DLL called UiWidgets that I created. The uic and moc and compilation worked fine.
Then I want to use this widget in my other project MyApp. I designed the interface in QtDesigner and added the MyOpenGLWidget. I promoted the QOpenGLWidget in QtDesigner to MyOpenGLWidget and set the header file to "../UiWIdgets/MyOpenGLWidget.h" (Since both the projects exists under the same solution directory, it should work)
But, after I coded the MyApp class and try to compile it, I got the following error.
1> Uic'ing MyApp.ui... 1> MyApp.cpp 1>c:\dev\projects\MyProject\MyApp\../UiWidgets/MyOpenGLWidget.h(18): fatal error C1083: Cannot open include file: 'ui_MyOpenGLWidget.h': No such file or directory 1> moc_MyApp.cpp 1>c:\dev\projects\MyProject\MyApp\../UiWidgets/MyOpenGLWidget.h(18): fatal error C1083: Cannot open include file: 'ui_MyOpenGLWidget.h': No such file or directory 1> main.cpp 1>c:\dev\projects\MyProject\MyApp\../UiWidgets/MyOpenGLWidget.h(18): fatal error C1083: Cannot open include file: 'ui_MyOpenGLWidget.h': No such file or directory 1> Generating Code...
My question is:
- The path is fine (I checked in the command line). Why is the error, did I miss somethin important?
- Is there a better practice to do so?
Hi and welcome to devnet
Does file "ui_MyOpenGLWidget.h" exist and where?
It looks to me like you have a path issue and "ui_MyOpenGLWidget.h" is somewhere located, but not in a folder of the path.
@koahnig Thank you for replying. The file is located at ProjectDir/GeneratedFiles/ui_MyOpenGLWidget.h. I wonder wouldn't it be enough to specify the path of only MyOpenGLWidget.h other than ui_MyOpenGLWidget.h? Since ui_XXX.h is generated by uic?
If you have only one projectdir I am agreeing, but I understood that you may have two.
When you setup a dll project all will be consistent within this project for compilation and linking. Typically the ui_*.h files are generated in a build folder. However, your project setup will know about it.
If you try to use the same header in another project (in your case MyOpenGLWidget.h), but the associated ui-file (in your case ui_MyOpenGLWidget.h) is not in the same folder, your project setup cannot know.
Thank you. That makes sense. So do you have any advice about how to use a custom widget in DLL? And after I modified this include in MyOpenGLWidget.h
and it complies and runs like charm. And indeed I added ".\GeneratedFiles" in my additional include directories.
But I still do not know the reason.
I am not using setups similar to yours. Therefore my advise might be wrong.
Anyway, I assume you have a dll project with follwoing structure:
- dllProject with MyOpenGLWidget.h
- dllProject/GeneratedFiles with ui_MyOpenGLWidget.h
- ProjectDir with your new project files
- ProjectDir/GeneratedFiles with some generated files for the new project
Since ProjectDir is your current project directory ./GeneratedFiles will point to ProjectDir/GeneratedFiles
Your INCLUDEPATH will hold at least dllProject ProjectDir/GeneratedFiles
you probably should add dllProject/GeneratedFiles
and you should be fine.
One note: You seem to use the backward slash '\' as it is tradition under windows. However, nowadays windows does also accept a foward slash '/'. I would recomment to use in general the linux compatible '/' also for any folder handling within Qt related files. Sometimes this may help you to prevent severe difficulties.
This post is deleted!