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. Need your opinion on resource of QTextDocument

Need your opinion on resource of QTextDocument

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 337 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.
  • CharlieGC Offline
    CharlieGC Offline
    CharlieG
    wrote on last edited by
    #1

    Hello,

    I want use resource and addResource of QTextDocument to load a html model and stylesheet.

    Here, my currently code :

        QTextDocument *tdContent = new QTextDocument(this);
        tdContent->setPageSize(contentSize);
    
    
        QFile styleFile(m_modelStyle);
        QString style;
        if (styleFile.open(QFile::ReadOnly | QFile::Text))
        {
            QTextStream in(&styleFile);
            style = in.readAll();
        }
    
        QFile model(m_model);
        if (model.open(QFile::ReadOnly | QFile::Text))
        {
    /// what is the best way for you ? Use QTextStream or directly use resource of QTextDocument ?
            /*
            QTextStream in(&model);
            m_totalHtml = in.readAll();
            */
            m_totalHtml = tdContent->resource(QTextDocument::HtmlResource, QUrl(m_model)).toString();
    
    
            tdContent->addResource(QTextDocument::StyleSheetResource, QUrl( "style.css" ), style);
            for (const auto i : m_dataModel)
            {
                QStringList tuple = i.toStringList();
                m_totalHtml.replace("$"+tuple[0]+"$", tuple[1]);
            }
        }
        else {
            addContent();
    
        }
    
        tdContent->setHtml(m_totalHtml);
        //tdContent->addResource(QTextDocument::HtmlResource, QUrl(m_model), m_totalHtml);
    

    If I comment tdContent->setHtml(m_totalHtml);and I uncomment the last line, it doesn't work.
    Do I make a mistake using addResource ?

    Thank you for help.

    Charlie.

    1 Reply Last reply
    0

    • Login

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