Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading python script and store as string at compile time?
Forum Updated to NodeBB v4.3 + New Features

Reading python script and store as string at compile time?

Scheduled Pinned Locked Moved Solved General and Desktop
stringpython
3 Posts 2 Posters 560 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lansing
    wrote on 9 Aug 2020, 20:44 last edited by
    #1

    I'm using C++ version of Qt, I want to read some python script and store them as strings at compile time. I tried copy and pasting them into the cpp file and read them as raw string literal. It works but since python script is space sensitive, they looks so ugly when pasted in a cpp file

                QString pythonScript = R"(import abc as apple
    print("1")
    def = "hello")";
    

    Is there better ways to do this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 9 Aug 2020, 20:49 last edited by
      #2

      Hi
      You could use a resource file and store a .py file there and load it.

      L 1 Reply Last reply 10 Aug 2020, 02:48
      2
      • M mrjj
        9 Aug 2020, 20:49

        Hi
        You could use a resource file and store a .py file there and load it.

        L Offline
        L Offline
        lansing
        wrote on 10 Aug 2020, 02:48 last edited by
        #3

        @mrjj

        Thanks I tried the resource system and it works.

        QFile file(":/python_scripts/script1.py");        
        file.open(QIODevice::ReadOnly | QIODevice::Text);
        QString pythonScript = file.readAll();
        
        1 Reply Last reply
        1

        2/3

        9 Aug 2020, 20:49

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved