I'm trying to build a demo application with Qt in Visual Studio 2019. I used the Qt VS Tools in the Visual Studio IDE, and the Qt Designer to create my user interface. I also used the Qt SVG module in order to use SVG images for my user interface.
I achieved a working project, which works pretty well in debug and release mode, as long as I run it from the Visual Studio IDE. Now I would like to distribute it as an independent .exe file. For that I tried to create a zipped archive containing the .exe itself, the required Qt DLLs, and of course the resources the interface requires.
The compiled .exe can be executed in its own dir without problems, however none of the images I added in the resources are visible. I tried several ways to resolve the issue, and read many tutorials explaining how to use and/or embed Qt resources in the exe file. None of them worked for me.
I already tried to:
Simply copy the images in the .exe dir, keeping their dir hierarchy or not, but only the .png and .jpg images were visible, all the SVG were lost.
Compile a Qt resource file (.rcc) using the Qt rcc.exe tool, and add it to the Visual Studio resources, not worked.
Generate a .pro file using the "Create basic .pro file..." menu item (which also generated a .pri file) and add the following line, without success:
RESOURCES += MyResName.qrc
Adding the below lines in various location of my source code (main form constructor, main() function, ...). Nothing worked:
QResource::registerResource("MyResName.rcc");
...
Q_INIT_RESOURCE(MyResName)
Playing around and mixing the above mentioned ideas, nothing worked.
So can someone give me an as simple as possible explanation about how to correctly build an .exe file with its required resources, which may work in an independent way, using Qt and Visual Studio 2019, in order to distribute it, respecting the following constraints:
The project is a C++ project developed with Qt and Visual Studio 2019.
The project uses Qt, has a .ui file built with Qt Designer, which embeds several SVG and/or PNG/JPG images, and in which these images are visible in design time and if the exe is run from the IDE.
The project uses a .qrc file pointing the images, SVG or not, required for the application.
The images were added to UI components through the styleSheet property, like that:
image: url(resources/images/im-dropbox.svg) center center;
Other resources files, like .pro, .pri, .rcc, ... may be generated without problems. The required resources are well embedded in the generated files (verified).
Please help me, because this situation gives me headache.
I'll try to cover all the issues i see, in the order i see them.
First you don't use the files from resources, the Qt resource file paths start with :/ for example to set an icon from resources (in C++ code) you will do it like:
a.setWindowIcon(QIcon(":/images/window_title_ico.png"));
Now, to use resources directly from Qt Designer, you'll need to add your .qrc file for each ui file (click on that "edit" icon and then "Open resource file") after that you can set the icons from resources, see the print screen (Qt designer started from VS)
Note: you can double check the generated .ui file (it's an xml file) to see if the icon paths start with :/ then you know you have done it right. //in the .ui file you'll see something like:
<pixmap resource="resources/resources.qrc">:/images/acceleration.svg</pixmap>
//notice the relative path to the .qrc file and the .svg file path starts with :/
And lastly to display .svg on deployment, i noticed that you need to deploy the Qt5Svg.dll too (the one from the: PATH_2_QT\5.XX.X\msvcXXX_XX\bin) deploying only imageformats\qsvg.dll is not enough.
Hope this help to clear things a bit!
Related
I created a new Blank Node.js Web Application in Visual Studio 2015, and I'm unable to add .tsx files to my project and compile them. When I do so, the created .tsx file is put into a Virtual Project instead, even though it is present in the actual project as well. The project is set to compile JSX expressions as React calls.
It took me some time to track down what's happening behind the scenes, and what happens is that when a .tsx file is created in the project (through Add -> New File), it is created as a Content entry in the project's XML file, instead of a TypeScriptCompile entry. This is clearly an error.
I can fix the issue by manually editing the project's XML file, but no way I'm willing to do that for actual production in 2016, with hundreds of files.
Step-by-step guide to reproduce the error
Create a new Blank Node.js Web Application project
Create a new .ts file in the new project
Create a new .tsx file in the new project
See that the displayed "host project" of the .tsx file (check the top-left corner of the editor window) says "TypeScript/JavaScript Virtual Projects".
How can I make it so that .tsx files are included in the project exactly how .ts files are?
Edit
This is not a problem with a HTML Application with TypeScript project, but that project type contains a lot of unnecessary C# bloat that I don't need.
I can fix the issue by manually editing the project's XML file, but no way I'm willing to do that for actual production in 2016, with hundreds of files.
This has to do something with the project template, and is likely a bug. A possible workaround in the meantime is creating the new file as a .ts file, and then renaming it to .tsx.
I'm trying to embed an application icon in an F# windows application, using the method described in the accepted answer to Changing F# application icon.
When I add the .res file to the application (either by setting Build/Other flags to --win32res:MyResourceFile.res or by setting Application/Resource File), the UAC prompt pops up when I start it.
I've tried:
Embedding an empty .res file (compiling an empty .rc to .res) - same result.
Creating a new console project, changing the output type to Windows and embedding the .res file - same result.
Deleting the .suo files just in case - same result.
What could make the addition of a .res file to an app cause UAC to kick in?
(Using VS2015 w latest updates, F# 4.0, .NET 4.6.1)
Edit:
I have created 2 minimal projects the same way, but one of them has the UAC problem and the other doesn't. I've compared the fsproj and sln files, but comparing them (Notepad++ compare plugin) I see no difference in any project setting.
Project files for ConsoleApp1, which does not have the UAC problem: http://s000.tinyupload.com/index.php?file_id=35796827731424697941
Project files for FixVS2015Update, which does have the problem: http://s000.tinyupload.com/index.php?file_id=30669246856403684470
Screenshot of KDiff3, comparing the .fsproj files:
Only file names and GUIDs are different, unless I've missed something.
Comparing the .sln files:
I can't find any differences there either.
Visual Studio Code (0.3.0 - 0.7.0) defaults to opening files in a new window, so if you double-click a file in the project view in Unity, or any log in the console, it will open a new window rather than opening the file in an existing window you already have open.
Visual Studio Code (0.5.0 - 0.7.0) will open a file in an existing window if you pass it the command line arg -r, however Unity will not let you customize command line arguments on OSX, it's a Windows-only feature.
Is there a way to open files from Unity into an existing window in Visual Studio Code (0.3.0 - 0.7.0)?
There is a way, but it's a pain. Create a shell script that calls Visual Studio Code and passes it the file path that Unity provides:
"/Applications/Visual Studio Code.app/Contents/MacOS/Electron" -r -g $1
exit 0
Then you need to make an .app from that shell script. I used a program called Platypus to make the .app. If you use Platypus make sure to check the 'Accepts Dropped Items` checkbox, it didn't work for me until I used this option.
Once you have the .app created you need to set that app as your External Editor in Unity.
Hopefully in the future Unity will allow custom arguments to be sent for OSX, not just Windows. Also it would be nice if Unity passed the line and column numbers to custom external editors, currently those details are only passed to certain Unity-recognized editors. There is really no reason I can think of that why they could not pass that information as additional arguments. Because that information isn't being passed that means you cannot configure this script to open up the file to line that an error might be on, which is a bummer.
Also, this entire answer would be unnecessary if the Visual Studio Code team would just add an option in the preferences to default to opening files in the existing window instead of defaulting to a new one. There are a couple of feature requests listed on their site for this currently, here's one: http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8740771-persistant-option-to-open-files-in-existing-window
Hi you can get full debugging support in VSCode for Unity using this plugin
https://github.com/dotBunny/VSCode
VS Code in Unity
This plugin works on both MacOS and Windows and gives you the following capabilities:
•An option to enable VS Code integration (Editor –> Assets –> Enable Integration), this updates your solution files and (more importantly) keeps them in sync. This also sets the preferred external tool editor in the Unity preferences.
*Note, the old “Sync MonoDevelop” option is now gone in the Unity editor from V5.2
•It writes out the necessary (and sometimes hard to find) VS Code configuration files, including the ability to hide “non-code” files in the editor (hides things like .sln, .csproj and the ever present unity .meta files)
There are a couple of other settings in there to help speed up the integration.
•Automatically launches VS Code direct to your project folder, EVERY-TIME. no longer do you have to worry about keeping that window open, or switching around if you work on multiple projects
One thing to be aware of, once you enable the VSCode integration, changing your preferred code editor in the External Tools preferences will have no effect as the plugin takes over opening code files.
I have created a new qmlproject using New File or Project… / Applications / Qt Quick 2 UI with Controls. I'd like to add resources (such as image files and fonts) to the project.
When I rightclick on the project, the entry Add Existing Files… is greyed out.
When I choose Add New… / Qt / Qt Resource file, Qt Creator creates a new resource file, but then pops up an error message that the file could not be added to the project.
When I drag an existing file from Finder to the project, Qt Creator open the file in a hex editor, but does not add it to the project.
I could not find any documentation on this, so this is why I would like to know: what is the standard way for adding a resource to a .qmlproject?
I'm using the version of Qt Creator bundled with Qt 5.2.0 beta 1
I don't think you can.
The type of project wizard you chose is documented here:
Qt Quick UI (in the Other Project category) creates a Qt Quick UI project with a single QML file that contains the main view. You can review Qt Quick UI projects in a preview tool and you need not build them. They do not contain any C++ code.
Qt Quick Controls UI is like Qt Quick UI, but using Qt Quick Controls.
The part in bold is key here, because .qrc files must be compiled into the application's executable, which can't happen when you don't have any C++ files to compile. Even if you had external binary resources, there's no QML API to register them as far as I'm aware; only C++.
Newer versions of Creator seem to recommend against it:
Creates a Qt Quick 2 UI project using Qt Quick Controls with a QML entry point. To use it, you need to have a QML runtime environment such as qmlscene set up. Consider using a Qt Quick Controls Application project instead.
I wouldn't recommend using the .qmlproject format. From memory, the last time I tried to deploy such a project to e.g. an Android device, it didn't work. You're better off using the "Qt Quick Application"/"Qt Quick Controls Application" project.
I have to create around 200 WP7 apps that are very similar. They differ only in the content, icons and name. So manually create them isn't a good idea so let's I've written a little tool, which does the following:
Copy the created template project
Copy the content files from a source directory to the copied template.
Change the app name, tile name and app id in the WMAppManifest.xml
Add the copied content files in the .csproj-file.
This works and the generated project opens error-free in Visual Studio 2010 and compiles without errors. The xap-file can be deployed on device and emulator.
The problems:
If I want to debug the app by pressing F5 in Visual Studio I get "The application could not be launched for debugging. Ensure that the target device screen is unlocked and that application is installed", both for device (which is unlocked and connected with Zune/WPConnect) and the emulator.
If I try to start the app on the emulator it closes immediatle after start. BUT if I start the app on my device it works like a charm. Crazy stuff.
The curious stuff: If I do the things which my little tool does manuelly I can debug the project from Visual Studio.
This only occures with my generated projects. Every other WP7 project (existing or newly created within VS) works and debugs error-free.
I tried to PCs: Win7 x64 with VS2010 Ultimate and an other one Win7 x64/VS2010 Pro and on both maschines I have the problem.
Maybe someone has an idea which causes the problem. Thanks for the help!
Edit: I've seen something new: The AssemblyInfo.cs file is located in the properties folder and correctly included in the csproj-file. But if I try to open the Assembly Information from the project properties all fields are empty and if I try to set them I get an error ("value is not in the expected range" or something like this).
I've got similar problem with some sample programs.
It turned out that I have to set in a Solution properties:
Active config => Debug|Windows Phone
it works for me
If they only differ in content, icons, and name, would it be simpler to make one complete app, copy it 199 times, and then just put the appropriate files into the correct directories?(if you made a tool to make templated projects, i'm sure you could do this with code too)
Plus that way if you ever need to change the program you can just recopy with that code again, but not copy the content, thus updating all of your individual 200 apps.