Qt 5.1.1: QWebView doesn't load local html file - c++

I've been struggling with an issue regarding loading a local html file. I'm going off the assumption that a QWebView is the correct way to be trying to display this file. My issue is that while I have the .html file visible when running in Debug, when I attempt to run in Release it is not visible. I am including the file in the appropriate directories, so that's no the issue. Are there any additional settings, libs, dlls that I could be missing? I've got the file specified to the QWebView in Qt Creator in the URL field of the QWebView. It is displayed like below:
file:///C:/devel/projects/myProject/myProject/Resources/page.htm
I've changed the file to a .html as well, it doesn't seem to make a difference.
Thanks,
-K
Edit: I've changed it temporarily to:
waiver_webView_2->setUrl(QUrl::fromLocalFile("file:///C:/devel/projects/myProject/myProject/Resources/page.htm"));
Unfortunately this still does not work. I've verified and the file does actually exist there. When I provide that location to the URL via the Qt Creator it works on my developer machine in release but not on a machine I deploy to, DESPITE the folder structure being absolutely identical.

The best I could find was getting the absolute path of the file first and then using that path with QUrl. There's a qt forum post on this topic which I'll put as a source bellow. It can be adapted to your code like so:
waiver_webView->load(QUrl::fromLocalFile(QFileInfo("page.htm").absoluteFilePath()));
QFileInfo also needs to be included.
source https://forum.qt.io/topic/23653/qurl-fromlocalfile-and-relative-path/4

Related

How to fix "This file is not part of any project. The code model might have issues parsing this file properly." bug in Qt Creator?

I just installed Qt creator (for the 10th time probably), and even when I follow the simple steps to create a new Qt Widget or Qt Console applications, I get this error. Extremely frustrated with various Qt Creator bugs. Help will be appreciate.
If you look closely at your workspace, you can see, that there are two projects. One project is called Sample, one project is called Widget. The active project is "Sample". You can tell that from the project browser as the Sample project is in bold letters. So building and debugging applies only to the Sample project.
The open file where you set your breakpoints in is "Widget/main.cpp", it belongs to the other non-active "Widget" project. So when you start the debugger, the environment warns you that this will not work. Completely correct behaviour.
Maybe try the following:
1- Ensure case sensitive typing of the file name and type the full path not just the name.
2- Delete configuration files that are automatically created.
3- Make sure the QT environment is setup correctly pointing to the required compilers, packages and resources.
4- Check if there are any missing environment variables on your machine.
The problem could be in the .pro
Check that you have the file into the source in the .pro

Qt application has unexpected QDir::currentPath

I am using QSettings in my Qt application to store prefences and all was fine until I start to run it on Linux mint 19. Default location for settings file is application folder, but now it is creating in users home folder.
QDir::currentPath() returns home folder, if I am running application by double click, and correct executable location if I am running it from terminal. I have never seen this before. Maybe somebody knows how to fix it and run application by double click from it's own folder.
Don't depend on current working directory (returned by QDir::currentPath()), because that can be basically anything. Looks like your desktop environment's file manager sets current directory to home folder when you run software by double clicking, and this is generally sensible, because that is usually what user would want, when opening files from the app etc.
If I read correctly what you want, that is path to application folder to store settings in, you need QCoreApplication::applicationDirPath(). But note that doing this will force you to install the application to user home folder (because you can't write to system folders like /user/local/bin, and you shouldn't change this by changing permissions, either).
Based on comments, it seems QCoreApplication::applicationDirPath() gives wrong directory, but QCoreApplication::applicationFilePath() gives correct path. If that is really the case, then take the file path, and remove the executable file from it. However, looking at the Qt source, this shouldn't be possible because applicationDirPath() already does just that...
I recommend you instead use QSettings as documented in its basic usage.

Get the config folder of a third-party Click-Once application

Currently I am messing around with a Click-Once WPF application. That application is some third-party application that was not developed by me. I also do not have access to its sources.
It is run on a Windows server periodically and automatically (using a self made launcher written in standard C++) by executing the corresponding *.appref-ms link that was placed in the start menu path on installation of the application. This works fine.
Due to periodically arising problems with that application my launcher needs to wipe all configuration files before starting it so I get a well defined run at all times. Those files are placed in one of the application's folders. That config path for its settings reads like this (I found it by searching the AppData tree manually):
C:\Users\<UserName>\AppData\Local\Apps\2.0\Data\WM4WPKCW.P5Z\67QVXD6C.0NT\<app>_f6187a2321850a68_0003.0004_1a67f9f1633c43fc\Data\AppFiles\
Please note that this config path is pretty different from the application path (which uses differently named folders):
C:\Users\<User>\AppData\Local\Apps\2.0\5HN2CKMO.MPL\YOL20MYR.O8L\<app>_f6187a2321850a68_0003.0004_f6ab8c93b3a43b7c\
Since this config path changes on each update of the Click-Once application I need to find it by code (preferably C++) automatically. Unfortunately I could not figure out a way to do this.
How can I make my launcher find the config path of the Click-Once application based on its *.appref-ms file?
From Raghavendra Prabhu’s blog entry “Client Settings FAQ”:
” If you want to get to the path programmatically, you can do it using the Configuration Management API (you need to add a reference to System.Configuration.dll). For example, here is how you can get the local user.config file path:
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Console.WriteLine("Local user config path: {0}", config.FilePath);
The code is C# (evidently), but shouldn't be that hard to translate to C++/CLI.
Raghavendra Prabhu further writes:
” If you need to store the settings in a different location for some reason, the recommended way is to write your own SettingsProvider. This is fairly simple to implement and you can find samples in the .NET 2.0 SDK that show how to do this. Keep in mind however that you may run into the same isolation issues mentioned above .
Disclaimer: I have not tested any of this.

How to specify a standard directory in a Qt project file

I have developed an application that I plan to deploy on Windows, Mac, and Linux. The program requires access to some files (scripts and the like) at run-time.
The installation process should install the files to a location that my application can later determine without user-intervention (or perhaps just a prompt allowing the user to change the location, if desired).
What is the best way to achieve this? I can't seem to find any way to:
1. Use a "standardized path" variable in the project file's INSTALLS statement. (e.g., my application could use QStandardPaths to initialize the location, but I can't figure out how to access this path from the INSTALLS statement)
2. Save the path to my project's QSettings (.plist, registry, whatever) for later retrieval
That leaves me with creating a custom project file and INSTALLS command for each environment, and then I still can't install to the user's directory because I don't know the user's name when I deploy the make command. It seems as if there must be a better way, but I can't seem to find any documentation for this. Am I just using the wrong keywords in my searches? Thanks in advance!
What standard directory? What type of getting that standard directory?
For instance, you can put such thing in your windows branch of .pro file:
win32 {
APPDATA_DIR = $$system(echo %APPDATA%) # should be %LOCALAPPDATA% as requested
message($$APPDATA_DIR)
}
Just unsure of what exact kind of standartized path you are talking about. QStandardPaths knows many. It makes sense to be more concrete to find the correspondence with concrete OS.
Also somewhat relative reply on mine, on how to check the correspondence with certain variable, etc: Qt .pro file - how to add conditioning on OSX version?
Maybe this class will help you
QStandardPaths documentation
But your problem is still little bit unclear for me.

SFML not loading image (Possibly due to placing in wrong place?)

I'm not sure whether I'm doing something stupid or visual studio is doing something wrong.
I've never really used C++ with VS before, but I managed to get SFML working, and now I cannot load images.
This is how I put the image in the project:
However when I write:
if (!tileTexture.loadFromFile("ConceptTile.png"))
return EXIT_FAILURE;
It returns EXIT_FAILURE.
Can anyone give an answer to why this isn't working?
If it helps that png file isn't appearing anywhere in the debug directories, just dlls, exes, and pdbs.
I've looked online to try to find out where I am supposed to put images but I can't find any articles or help no matter what keywords I type.
Make sure you change the file properties within the project to copy it to the output directory. By default (and without further paths given in the string) SFML should look for the file in your working directory. You don't have to add image files to your project, if you ensure they're at the right place. Also make sure to not include them as resources (as SFML won't be able to load them without some additional code).
Open Windows Explorer and move to the folder that contains the C++ files and paste the image there and it shall work or make a folder and change the directory in code, for example, if you name the folder images :
(!tileTexture.loadFromFile("images/ConceptTile.png"))
return EXIT_FAILURE;
and it shall work.