Skip to content
  • 0 Votes
    10 Posts
    827 Views
    V

    @JonB said in Trouble Running Python Script in Qt - Using QRC Resources:

    @Veltroniv

    I built an .exe file from my .py file with all the dependencies (included libraries etc...).

    I presume you mean that whatever tool you used to generate a .exe from the .py source embeds a standalone Python interpreter into that executable, so no external Python is needed?

    yes, i guess. Its working properly so...

    And, just checking, what did you use to "gathering the path to exe file"? I assume you mean to the top-level executable of your Qt application, and then you locate the other executable generated from the Python script because you know it's relative to where your top-level executable will be installed?

    Yess, thats correct. It might not have been clear.

  • 2 Votes
    13 Posts
    4k Views
    F

    @JohnKS Wow, I just spent like an hour trying to figure this out and copying detailed tutorials verbatim to try and get it working and it's this non-default flag that apparently doesn't always need to be set seeing as it doesn't appear anywhere in Qt's examples. It would be really helpful if this was mentioned more prominently somewhere.

  • 0 Votes
    4 Posts
    693 Views
    semlanikS

    @Kevin470
    The qt_standard_project_setup function doesn't set CMAKE_AUTORCC flag, only UIC and MOC. So you need to add:

    set(CMAKE_AUTORCC ON)

    before calling qt_add_executable.

  • 1 Votes
    3 Posts
    1k Views
    D

    So, after long time, finally I can fix it.
    I don't know why, but *.ttf font file is works fine.
    Qt says support both otf and ttf file, but it's not.

  • 0 Votes
    1 Posts
    232 Views
    No one has replied
  • 0 Votes
    1 Posts
    267 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    P

    First off, thanks for your time.

    I've tried that yeah - you can see that I've made the default index_file "qrc:/index-light.html" in the load_args function. It's here in the code.

    When writing to qDebug() the string is correctly "qrc:/index-light.html", though nothing is shown in the webview... I've tried changing it to "qrc:/light.css" and then it correctly shows the css in the webview (the code in plaintext).

  • 0 Votes
    1 Posts
    459 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    A

    @JKSH The branch I've been copying from didn't include some of the folders that were present in the 'Resources' section. Shouldn't have taken me this long to figure it out. Thank you.

  • 0 Votes
    4 Posts
    2k Views
    S

    Ok so I managed to import the html by modeling my code similar to the example with:

    QString code = QStringLiteral("qt.jQuery('#first_page').load('html/first_page.html');"); //you can even nest it with: QString code = QStringLiteral( "qt.jQuery('#first_page').load('html/first_page.html', ()=>{" "qt.jQuery('#border_content').load('html/border_content.html', ()=>{" //some other html "qt.jQuery('#last_page').load('html/last_page.html');" "});" "});" );

    unfortunately I now cannot use the qwebchannel.js script anymore and my css gets screwed :(
    even loading it with:

    QFile script_file(":/qtwebchannel/qwebchannel.js"); if(!script_file.open(QIODevice::ReadOnly)) qDebug()<<"Couldn't load Qt's QWebChannel API!"; QString qt_script = QString::fromLatin1(script_file.readAll()); script_file.close(); view->page()->runJavaScript(qt_script);

    did not help. Since it is a small project and I am on a short deadline right now I will put everything in one html file and mark this question als solved.

  • How to read file from QRC?

    Solved General and Desktop
    4
    0 Votes
    4 Posts
    3k Views
    mrjjM

    @Dariusz
    Hi
    Thats why i often use the copy trick :)
    ctrl+k type some of the name, press enter, right click and copy
    Almost as fast as writing it when i have nested folders.

  • Module inside a qrc file

    Unsolved QML and Qt Quick
    2
    0 Votes
    2 Posts
    486 Views
    dheerendraD

    You need to include qrc file into project. You can create RCC file and use it as well.

  • 0 Votes
    3 Posts
    1k Views
    Michael RozshkoM

    You are right! It is my error, rebuild all project with full delete old directory and all work fine. Thanks for fast and good answer!

  • 0 Votes
    2 Posts
    1k Views
    jsulmJ

    @noone You will need to extract the content from qrc file to some location writable by your application and then load it from there in webview.

  • 0 Votes
    5 Posts
    3k Views
    Pablo J. RoginaP

    @Maluna34 maybe the qrc file mechanism is not the best approach for what you intend to use; however you only know your actual requirements.
    From documentation about Qt resource system:

    The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.

    so a music file for a whole opera concert is not a suitable candidate for being stored in the qrc file as it ends up into your executable.

    Given that said, you could get the file from the resource and save it somewhere to disk so the external tool can access it.

    QFile::copy(":/sounds/ocean.mp3", "/tmp/ocean.mp3");

    you can even use QTemporaryFile to avoid worrying about file naming and deletion.

  • 0 Votes
    7 Posts
    5k Views
    S
    //copy whole <from> directory to the folder <to> void copyDirectoryNested(QString from,QString to) { QDirIterator it(from, QDirIterator::Subdirectories); while (it.hasNext()) { QString file_in = it.next(); QFileInfo file_info = QFileInfo(file_in); QString file_out = file_in; file_out.replace(from,to); if(file_info.isFile()) { //is file copy qDebug() << QFile::copy(file_in, file_out); qDebug() << file_in << "<----" << file_out; } if(file_info.isDir()) { //dir mkdir QDir dir(file_out); if (!dir.exists()) qDebug() << "mkpath"<< dir.mkpath("."); } } }

    then use above function :

    copyDirectoryNested(":/<qrc_folder_location>",<writing_location>); copyDirectoryNested(":/DefaultAppData",app_data_location);
  • 0 Votes
    2 Posts
    2k Views
    T

    @xLlama

    You did not open your file for reading as indicated by the error messag "device not open".

    http://doc.qt.io/qt-5/qiodevice.html#open

  • 0 Votes
    8 Posts
    12k Views
    H

    @Jason-Wright Thanks for your solution. Help me solve the same problem.
    You can also remove 'as Components', then don't care this alias when use your 'Navigation'.

  • 0 Votes
    3 Posts
    3k Views
    raven-worxR

    @ericg22
    You can simply set properties of widgets via QSS. Most basic types are parsed. Even enums can be used by name when registered to the meta system.

    class MyWidget : public QWidget { Q_OBJECT Q_PROPERTY( QColor CustomColor READ ... WRITE ... DESIGNABLE true ) Q_RPOPERTY( QFont CustomFont READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( QString CustomString READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( int CustomInteger READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( QIcon CustomIcon READ ... WRITE ... DESIGNABLE true ) Q_PROPERTY( MyEnum CustomEnum READ ... WRITE ... DESIGNABLE true ) Q_ENUMS( MyEnum ) ... enum MyEnum { MyEnumValue1, MyEnumValue2 } }

    example qss to set properties:

    MyWidget { qpropert-CustomColor: rgba(...); //also rgb(), hsv(), rgba(), named-colors, #XXXXXX, etc. are possible9 qproperty-CustomFont: "serif,-1,14,5,0,0,0,0,0,0"; // see QFont::fromString(): Font-Family, pointSizeF, pixelSize, QFont::StyleHint, QFont::Weight, QFont::STyle, underline, strikeout, fixedPitch, rawMode qproperty-CustomFont: "Times New Roman,12"; //should also be possible qproperty-CustomString: "Any string..."; qproperty-CustomInt: 8253; qproperty-CustomIcon: url(:/path/to/qrc/resource/icon.png); qproperty-CustomEnum: MyEnumValue2; }