I created my program in QtCreator, but now I have to move it to VS2012 (with Qt add-in 5.2.1). But visual doesn't find the ui files. I get:
error C1083: Cannot open include file "ui_window.h": No such file or directory"
Yes, I write #include "ui_window.h"
I tried two ways to do that:
creating new project and adding existing files
creating new project and creating new classes, and then copy code from old files to new files (named the same)
If anyone knows where the problem is?
I have had the same issue.
Does it create a header file "ui_window.h" from a file "window.ui" and put it to a directory $(ProjectDir)\GeneratedFiles?
Also you could try to compile "*.ui" file by right mouse click/compile or Ctrl+F7
If Visual Studio doesn't compile the file then check properties of the "*.ui" file:
1) check "Configuration properties/General/Item type: Custom Build
Tool"
2) check "Custom Build Tool/general/Commad Line, Description and
other arguments".
If it's empty or not set than try to reinstall "Qt Visual Studio Add-in".
Hm, I had the same problem, In my case i fixed it by first clicking on the .ui form file in visual studio, creating some qui in qtDesigner, then I commented out the include causing the problem, built the solution using release mode, got errors, re enableled the include file, and Voila it works perfectly..
Related
I am programming a Qt application in MS Visual Studio Community 2019. I am trying to add an icon to my application window with the following command, and I also have the corresponding file my_icon.ico mentioned in the .qrc file:
setWindowIcon(QIcon(":/my_icon.ico"));
When I build and run my program in VS, everything is perfect - the icon replaces the standard one. However, when I make a release and try to run the resulting stand-alone executable, the icon is NOT shown! This is particularly weird as images which I also mention in the .qrc file (pictures for buttons) are on their places.
I have tried to put my_icon.ico alongside the .exe file, but with no result.
I give up, please give me a clue what might be happening here.
Thanks to chehrlic, I understood that it was as simple as running the windeployqt.exe on the .exe file build by the Release configuration by Visual Studio.
This will link all required libraries dynamically.
Avoid using this tool while the .exe file is inside the Release folder as it will create many other files & folders near .exe file. I have copied my_app.exe to a fresh directory and ran the following command from it:
C:\Qt\5.14.1\msvc2017_64\bin\windeployqt.exe my_app.exe --release
See https://doc.qt.io/qt-5/windows-deployment.html for more details.
So, I encounter another interesting "no such file or directory" error in my program.
The interesting thing is, when I typed the classes I include in my source code, which are QGraphicsItem and QGraphicsView in this case, no warning was given. But when I tried to built it in Qt creator, it raise an error and told me that "C1083: can not open include file:No such file or directory". (The header file both locate at D:\Qt\Qt5.4.1\5.4\msvc2013_64\include\QtWidgets)
Also, I went check the include path in my qt5.4 file, which is D:\Qt\Qt5.4.1\5.4\msvc2013_64\include in his case, I did exactly find the two header files.
Has any one met this error before? Can explain it?
And by the way, which is the default include path in qt creator and how to change it?
You should check your .pro file for this line:
QT += core gui widgets
I would recommend to add widgets to your QT variable.
Yhis should solve your problem with path to all headers, which are realted to QtWidgets.
Don't forget to rebuild your project after editing .pro file.
In case you are building it from console you should:
cd to your project dir
Run qmake
Than run make
In case you are using QtCreator you should use Rebuild option
I'm trying to run the texteditor.pro file in the QtSDK\Examples\4.7\tutorials\gettingStarted\gsQml directory with Qt Creator. When I try to build the project I get a window that says
Could Not find the executable, please specify one
with three fields to load files. Snapshot of the dialog box.
I'm running windows 7 64bit, with Qt Creator 2.4.1
I've solved the problem it was a missing dll file, but the executable didn't ask for it, so I put all the dlls from Qtcreator -> bin in the same folder with the *.exe file, then I deleted file after another until I figured out what files are required.
* It is a brute force way, but It did the job.
* Here is the file that were missing (libEGL.dll)
This project is not created in the normal 'Qt-executable' kind format. Rather its a 'plugin' kind project. So you cant run it directly like other projects.
[If you will open the project files you wont find a main() function!, which is supposed to be the entrance point usually for a C++ Application. All you have are a couple C++ classes. Take that as a hint]
About this example they have given the complete details here. And I quote:
We need to compile the file dialog C++ plugin before the text editor
can run. To compile, enter the gsQml directory, then run qmake and
compile using make or nmake, depending on your platform. To run,
launch qmlviewer and open the texteditor.qml file.
Else:
You create your own project.
Add these class files and the respective qml files to this project.
Add a main and create the respective objects required.
Make an application viewer and give "texteditor.qml" path as its source.
I had the could not find executable window pop up in my face in Ubuntu 12.10.
Here's how I got the "error":
Created a folder named Project;
Inside it, I ran "qmake -project" and then "qmake";
Created a main.cpp file inside the folder;
Opened the Project.pro file with Qt Creator and added the line "SOURCES += main.cpp" to it;
Pressed Ctrl + R to build and run the project.
Later on I deleted the folder and created it again, but this time creating a main.cpp file before trying to run any commands. I opened the .pro file with Qt Creator, created a main function in the main.cpp file, and pressed Ctrl + R, and it built and ran!
I have a project on Visual Studio 2010, which uses integration with Qt 4.8, some of boost features and all this stuff is versioned with SVN.
Everything was fine: I moved solution folder from one place to another, compiled it on different computers.
But once I've renamed solution folder, and when I tried to build the project - compiler wrote only one error:
Error 1 error MSB6006: "cmd.exe" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets 151
But when I return old solution folder's name - everything builds without any errors again!
As i figured, compiler cannot use custom build steps for *.ui files and stops whole build process.
Probably, there is some issue with absolute pathing, but I cannot find it second day :(
As it often happens, the answer was hiding right on the ground.
While observing build output I got lines like this:
1> Uic'ing frmserver.ui...
1> File 'C:\Users\Theurgist\Desktop\JamServer (?????)\JamServer\frmserver.ui' is not valid
This issue was all because Qt compiler tools can't work with unicode-containing paths correctly (at least up to version 4.8)
There must be some references to the old folder location in either your .sln file or your .vcxproj file(s).
You should be able to fix this by:
Closing Visual Studio
Opening your .sln file and all the .vcproj files it loads in a text editor of your choice
Doing a search-and-replace for the old folder name, changing it to the new folder name.
My Qt project have two source files with the same name but in different folder.
The pro file is:
SOURCES = A/Test.cpp
SOURCES += B/Test.cpp
It can generate Visual Studio solution file via Qt Visual Studio addon, but it won't work because the generated object file have the same name: Test.obj.
That will cause LNK2001 unresolved external symbol because one of Test.obj is overwritten.
How to write proper pro file to deal with that?
Before Qt 5
You can try adding that line to your .pro file:
CONFIG += object_with_source
But as the option name implies, the .obj files will not be created in the out-of-source / "shadow build" directory.
Qt 5 and older
That option has been replaced by object_parallel_to_source in Qt 5, which should work with the shadow building.
You should consider splitting your solution in multiple projects, but it depends if each one of those folders could represent a project by its own.
If you choose this solution, you will have to write one .pro file per project. The usual way to go is to write a 'generic' *.pri file which is included from every *.pro file:
folder1.pro
TEMPLATE=lib
TARGET=folder1
include( ../common.pri )
folder2.pro
TEMPLATE=lib
TARGET=folder2
include( ../common.pri )
common.pri (in parent directory)
SOURCES += *.cpp
HEADERS += *.h
# etc.
Obviously the contents of each pro file depends on your solution.
If you don't want to split the source files in multiple projects, the easier solution would be to rename one the conflicting files, I guess.
I recently came across this issue, too. Splitting the project into subprojects made everything much more complicated, and -at least on my first attempt- flat-out didn't work. Then I tried CONFIG += object_with_source and CONFIG += object_parallel_to_source, but both did't seem to work with my Qt version.
So this is how I solved it (for Visual Studio 2010; I don't know if works the same with other versions):
If the project were an ordinary Visual Studio project, not one generated by QMake, you could solve it as described here: Visual Studio 2010 & 2008 can't handle source files with identical names in different folders? (changing the output dir of object files to a relative dir by appending %(RelativeDir) in the project settings "C/C++" > "Output Files" > "Object File Name").
Obviously, you don't want to do this by hand everytime you create a new Visual Studio project with QMake, so why not automatize it? After all Visual Studio project files are but ordinary XML files. Looking at the diff before and after setting the options reveals it's saved in a single unique tag called ObjectFileName.
So I wrote this Python script:
import sys
filename = sys.argv[1]
f = open(filename, "r", -1, "utf-8-sig")
lines = f.readlines()
f.close()
f = open(filename, "w", -1, "utf-8-sig")
for line in lines:
line = line.replace("</ObjectFileName>", "%(RelativeDir)\</ObjectFileName>")
f.write(line)
f.close()
..and use it like this in my bat-file that I always call to create the Visual Studio project:
qmake -tp vc myproject.pro
#cd ../scripts
unflatten_vcproj_obj_output.py "../src/myproject.vcxproj"
#pause
Not a beautiful solution, but it works.
One solution is to rename the files:
A/a_Test.cpp
B/b_Test.cpp
It's a bit ugly, but its simple and the class names can stay the same.