I found a QSS file online (http://tech-artists.org/forum/showthread.php?2359-Release-Qt-dark-orange-stylesheet) that I would like to use as the style in my app. I have been trying multiple different ways of importing this file into my program, but every time I run my program, it does not successfully open the file.
Currently I have the file saved as myStyle.qss in the same directory as my project. I have also been hearing about inserting the file into a qrc file. Is this necessary in order to open it, or just a convenient way of storing the file?
My code so far is:
QApplication a(argc, argv);
QFile file(":/myStyle.qss");
file.open(QIODevice::ReadOnly);
QString style(file.readAll());
a.setStyleSheet(style);
file.close();
I have seen this block of code in multiple different places, so I am fairly certain that I have the majority of it right and that my main problem is just in my file placement, or that I have the wrong file path written down.
Thanks!
":/myStyle.qss"it is path which uses for Qt resource system. As you said, this file in the same directory, so try to set nornal path, "myStyle.qss", but be carefully because Qt will search this file in the build directory, so you should place file in build directory.
But when your qss file will be done, then save it in the resources. There are many examples how to do this in the web (for example this. In this case you will need your current path ":/myStyle.qss"
Why do you need resource?
Resources are build into exe file so you never lost this files, user can't delete it or rewrite. If user delete your qss file, all your style will fail, so you should protect it.
I'm developing html/css in Sublime. I'm writing my css with sass and using Sublime's build system to generate the css file on file save. It's also configured to upload on save using the SFTP plugin.
My problem is that the generated css file doesn't get uploaded as that isn't the file I've directly saved. I've tried to see if there is a way for the SFTP plugin to upload all files that have been modified locally, but it doesn't seem to support that.
Is there anything I can do to achieve this?
I'll throw my solution into the mix, just in case anyone stumbles on this as I did and wants to stick as close to a solely ST-based workflow as possible. If you're using the SFTP package for ST, there is an option to monitor files for external saves.
Unfortunately, using the ST build system to compile my SASS somehow slipped by SFTP. SASS CLI's watch utility, however, triggers the upload just fine. Once set, presuming the target file remains open, SFTP will upload it after each build.
To recap,
Open target file, followed by the command palette. Enter SFTP: Monitor File (Upload on External Save)
Start whatever CLI watch/build utility you prefer, for me, Sass: sass --watch app.scss:app.css
Leave target file open, otherwise the SFTP monitor seems to cease.
Enjoy!
NOTE: You can also enable file monitoring from the sidebar by right clicking on the file you wish to monitor and selecting...
SFTP has an option for that. Search on Package control for SFTP > Monitor file. Once selected, "SFTP monitoring" will appear on bottom command info. Now on every save, both sass and complied css will be uploaded to their respetive folders.
Because Sublime SFTP doesn't seem to support this, you'll probably have to go a different route.
I would recommend using something that monitors your css folder, and automatically uploads any changes to your server. Using good ol' fashion WinSCP (if you're on Windows) would work, but any way to sync folders works.
http://winscp.net/eng/docs/task_keep_up_to_date
I ended up scrapping SFTP and using ExpanDrive. Fits my workflow perfectly.
I'm still using Sublime SFTP to upload script files (js/css/php etc). Usually I press shortcuts to upload opened files (Ctrl Alt U + N). But it was annoying especially with frequent trial disclaimer window.
I wrote a simple tool on nodejs which monitors project folder and uploads any file on its change. It's not perfect but made my workflow much comfortable: https://github.com/liberborn/live-uploader.
Also note that you can map a local copy of your files to the remote copy, by opening the local folder in Sublime, then right-click on it in the sidebar, and select SFTP/FTP -> Map to Remote... to set up the connection, making sure to enter the appropriate remote_path to map the folder to.
Then you can do your build/compile, open the local compiled file(s), right-click on the code, and in the SFTP/FTP menu, select the Monitor File option.
Now when you build again in future, with the compiled file(s) still open, they will get uploaded to the server shortly afterwards (as well as being refreshed in Sublime when you switch tab to view them).
There's a way to force Sublime SFTP plugin to upload compiled files, if your CoffeeScript/Sass/Less files are compiled when you save a file.
Go to Sublime Menu → Tools → Developer → New Plugin..., and copy-paste the code below:
import sublime, sublime_plugin, re, os
class SftpAutoUpload(sublime_plugin.EventListener):
def is_remote_file(self, file_name):
while file_name != os.path.abspath(os.sep):
file_name = os.path.dirname(file_name)
sftp_config = file_name + '/sftp-config.json'
if os.path.exists(sftp_config):
return True
return False
def on_post_save_async(self, view):
window = view.window()
file_name = view.file_name()
# Upload compiled files to SFTP when saving a file (Coffee, Sass, Less)
if self.is_remote_file(file_name):
extensions = { 'coffee': 'js', 'less': 'css', 'sass': 'css' }
for extension, compiled in extensions.items():
matches = re.match('^(.*)\.'+extension+'$', file_name)
if matches is not None:
compiled_file = matches.group(1) + '.' + compiled
if os.path.exists(compiled_file):
new_view = window.open_file(compiled_file)
window.run_command("sftp_upload_file")
new_view.close()
Save the file as sftp-auto-upload.py. Restart Sublime.
What the plugin does is the following:
it checks if you're editing a CoffeeScript, Sass or Less file;
if a compiled file exists, then the compiled file is opened in Sublime
SFTP: Upload File command is executed, and the compiled file is closed.
All this happens almost instantly, so you don't even notice that a new tab was opened.
The code can be improved, but it does the trick.
Is there an application that can create a standalone HTA, which means no need 'mshta.exe' to run and not leaving any temporary files? i've try 'htaedit' but it need 'mshta.exe' and leave temporary files.
I don't think that hta can be run standalone. it is more of an interpreted language which is interpreted by mshta.exe. sort of like how java byte code is interpreted by the jvm
You could create a self extraction drive using iexpress.exe which :
zips a copy of mshta.exe and your hta file
unzips them to a temporary folder at runtime
and runs a specified command. eg : mshta <the hta filename>.hta
iexpress is commonly used to created quick and dirty installers.
I came to know of this process while finding a way to convert .bat / .cmd files to .exe
I use fopen(filename.c_str(), "rb"); in Qt with images resources.
But fopen wants a full path. It doesn't work if my filename is :/images/img.png!
fopen is not part of Qt. Qt's resource system only works with Qt classes. See the Qt documentation of Using Resources in the Application for details.
The Qt classes which work for resources first check if the given filename starts with the resource marker (:) and if so, they look up the resource internally (no physical file is opened!), otherwise, they open the physical file. Note that resources are included in the source code of your application (as a simple array of bytes) during compile time (using the Qt resource compiler) and read using a special resource reader in Qt internally, which can treat the resource file as it would be a physical file, but it still isn't.
What happens if you pass a resource file path (starting with :) to fopen? fopen tries to read a physical directory called : and searches in this directory for the subpath you provided. Of course, no such directory exists on your harddrive, since the file is part of your executable file. (And please don't try to read the resource file manually from within the executable by opening the executable using fopen and seeking to the resource!)
In your concrete situation: Are you trying to read the image using an external image reader? Qt has its own PNG reader. Just call the QImage(QString filename) constructor.
I want to read a .PDF file in Qt. I placed my .PDF file in the resource(qrc) folder.
How can i read the PDF file from there? I want to load a PDF file on the click of a button.
Read your pdf file via QFile, resource access is done by prepending the path in the resource with a ":".
Qt does not natively support displaying PDF documents (it can export them using QPrinter though). You can do it through third-party libraries such as Poppler, see this Qt Quarterly edition on how to do it.
FWIW the resource access information is the docs, and the PDF stuff I got off Google in 30 seconds. I expect a bit more research effort for someone with 7K+ rep points.