I have developed a program for a customer which includes a functionality to save and print PDF files. In this PDF file there should be a company logo attached.
I am using the QPrinter function to both create and print the PDF file. To add the logo I use the function drawPixmap. The logo itself is a JPG file. Originally I just added the file to my program folder and used QDir::currentPath() + "/" + "logoName.jpg". It worked flawlessly on my computer but at the customer it can not load the file using the load() function from QPixmap:
QPixmap companyLogo;
companyLogo.load(QStringPathToFile);
I have verified that the string is correct using entryInfoList() and compared it to the path I send to QPixmap.
I learned about resource files in Qt and how you could add a resource, like an image, to the binary. Again, it works flawlessly on my PC but at the customers PC it fails to load. I have verified the behavior on a secondary PC here in the company.
companyLogo.load( ":/logo/CompanyLogo.jpg" )
It seems like a such simple thing to do. But I am always hit a wall with this logo. Do anyone have any information how I can get this logo/image to load properly when deploying my Qt program to another PC?
You have to deploy jpeg plugin from /plugins/imageformats/qjpeg.dll
Have a look here about how to deploy on windows
Related
I'm having trouble with the transportability of my URDF files. Specifically I'm unable to get them to load in Foxglove Studio. Is it possible to add a URDF as an attachment in an MCAP file so that it's somehow fully encapsulated and just opens by robot definition at the same time as visualizing my robot data?
I've tried opening my URDF file directly in Foxglove Studio's web client and it fails. I seem to be able to open it in the desktop tool.
See the work in progress here: https://github.com/foxglove/studio/pull/4725
The basic idea is all asset fetch() requests go through a proxy function in the Studio data source (player). For MCAP, the player checks for an attachment with the name equal to the requested URL, such as package://foo/bar.dae and returns that if present, otherwise falling back to fetch().
My Qt C++ project involves dynamically creating and working with SQLite databases.
I'm encapsulating everything to do with the databases inside a class called Database. Here is my method to either create a database file if it doesn't exist, or open it if it does:
void Database::connectDB(QString databaseName)
{
QString fPath = QCoreApplication::applicationDirPath();
fileName = fPath + "/DBs/" + databaseName + ".db";
db = QSqlDatabase::database(connectionName);
db.setDatabaseName(fileName);
}
connectionName and fileNameare QStrings created elsewhere and are valid. To put it simply, this code works. But only when run from Qt Creator. I've verified that the absolute path I feed to setDatabaseName overrides the working directory as shown in the Qt Creator project settings. I do have to manually create the folder DBs. Perhaps that's not the best way to go about it, but I don't think it impacts this situation. After all, I have to create it before running from Qt Creator too.
I deploy on Windows 10 using the steps from the following video: https://www.youtube.com/watch?v=8qozxqSZQEg
I think the --quick argument is for Qt Quick, which I'm not using. I've tried with and without.
After deployment, the application looks like it's working, but the databases it needs are never created, so it eventually crashes. It surprises me that it doesn't immediately crash. I could be mistaken, but it almost seems that it's creating the first few databases in memory. Some information that should only be available by reading data previously entered into a database does show up. But not if I close and restart.
I've read this question and the linked questions, but they don't really have much to do with the exact nature of this issue: Path to the project current dir in qt
I can't wrap my head around why this isn't working. I've created DBs folders in every parent folder as well, just to be sure. Nothing. The files are simply not created. It works in the IDE, not once deployed. What is Qt Creator providing that isn't available to the application after deployment?
The compiler I'm using is msvc2015_64, if that matters. If there are any other details I'm leaving out that could be helpful, please mention them. I'll edit them in.
I wrote a Qt widget application. In the file menu I want to insert an MS word document as a user manual. Is there any way to do it? I checked Qt help and various blogs but none of them gave me a clear solution.
If it is only manual then it is not necessary to embed MS Word inside your app. Maybe try to open needed document with Word installed in computer. Try this code:
QDesktopServices::openUrl(QUrl("file:///G:/tst.docx"));
Just set needed path. As doc said:
If the URL is a reference to a local file (i.e., the URL scheme is
"file") then it will be opened with a suitable application instead of
a Web browser.
If you want to embed it in your application executable, just insert your .docx file as a resource file. To open the docx file from resources, you should first copy it to some location for example in the application directory path :
QFile HelpFile("qrc:/myFile.docx");;
HelpFile.copy(qApp->applicationDirPath().append("/myFile.docx"));
Next you can open it by :
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath().append("/myFile.docx")));
I'm develepping a BB10 mobile application using the momentics IDE.
I'm trying to save somes images coming from server into the "assets/images" folder using the Qt QFile object (you can see the code below) :
m_file = new QFile(argSavingFilePath);
if (m_file->exists()) {
m_file->remove();
}
m_file->open(QIODevice::WriteOnly);
m_file->write(argDataLoaded);
m_file->close();
m_file->~QFile();
It seems that is working but even if I exit out of the screen in question with the back button and then return it still doesn't show the latest image. It only works when I exit the app completely and launch a new instance.
According to this forum [link], they said :
"What's happening is that when you first load the image it gets read from the file system and then cached in memory. The app never goes back to re-read the image from the file. You would have to initiate that yourself."
How should I initiate the cashed memory myself ? is this the only solution ?
Whether the data is cached in memory or not is immaterial. The asset directory, in fact everything below and including the app directory is protected and immutable.
If you want to store data from a server the place to put it would be in data if you want it to persist, or tmp if not. Data in the tmp director is subject to removal by the OS when storage is needed for other things.
See: https://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/file_system.html
I have an C++ app I built which is registered as the default handler for a file with a specific extension. So when I download one of these files with Firefox from a website, it downloads it to a temp directory and then shell executes my app while passing the full path to the downloaded file on the command line.
What is the best way to figure out from the external app what the original download url of the file was, given only it's path on disk? Can I use XPCOM API calls to inspect the FireFox download manager database?
I've figured out that this data get's stored in the "%APPData%\Mozilla\Firefox\($profile)\downloads.sqlite" file which is a SqlLite db file, but I really rather not try to open this file directly as FireFox has an open write handle to the file while running.
After perusing the Mozilla developer center for a while, I ran accross the nsIDownloadManager service, which seems to be just the thing. But I can't seem to get access to it from XPCOM in a separate process?
Here's the code I am using:
nsresult rv;
//init XPCOM
nsCOMPtr<nsIServiceManager> servMgr;
rv = NS_InitXPCOM2(getter_AddRefs(servMgr), nsnull, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
//Get a download manager instance
nsCOMPtr<nsIDownloadManager> downloadMgr;
rv = servMgr->GetServiceByContractID(NS_DOWNLOADMANAGER_CONTRACTID,
nsIDownloadManager::GetIID(), getter_AddRefs(downloadMgr));
NS_ENSURE_SUCCESS(rv, rv);
When I run this, the GetServiceByContractID() call returns 0x8007000e, which is defined in nsError.h as NS_ERROR_OUT_OF_MEMORY. (which I find very weird).
Any ideas here? Am I barking up the right tree?
No, you can't access Firefox's XPCOM objects from an external process, and you also shouldn't open the sqlite database while Firefox has it open. I don't know that there's any straightforward way to do what you want without writing a Firefox extension that has access to the Firefox internals.
I'm a little hazy on the details right now, but, assuming that your download is served with a custom MIME type, it's possible to register a handler for that type; your handler can then cancel the download and pass the URL to your application.