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?

Reading python script and store as string at compile time?

Scheduled Pinned Locked Moved Solved General and Desktop
stringpython
3 Posts 2 Posters 536 Views
  • 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      2
      • mrjjM mrjj

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

        L Offline
        L Offline
        lansing
        wrote on 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

        • Login

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