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. Retrieving data from XML file via XQuery slowing down Qt application?
Forum Updated to NodeBB v4.3 + New Features

Retrieving data from XML file via XQuery slowing down Qt application?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.0k Views 1 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.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hey,

    I have recently added a function to my application that lets it query an XML file via XQuery to get some data. This function is automatically executed when the app launches. Ever since I added in this function, my application takes an annoyingly long time to launch, sometimes up to 20 secs. Before I added this function it launched very quickly. I am fairly certain that this function is the offender. Does calling an XQuery file to query an XML file and return the results really slow down applications this much? I plan to be using a lot of XML/XQuery in conjunction with Qt in the future and it would be nice to not have to wait half a minute for an app to launch. I know querying anything will take some time, but Im just querying a small, local XML file so I don't see why it should take so long. Any ideas on how to speed it up?

    Thanks!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DBoosalis
      wrote on last edited by
      #2

      Is putting the file parsing in another thread an option ? At least it will not slow down the GUI. But have to agree with you that something seems wrong for it to take 20 seconds. Why don't you post the code so we can take a look at it, might be something obvious

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nicky j
        wrote on last edited by
        #3

        the file parsing is related to the GUI because its retrieving text to place in QToolButtons.
        Heres the code:
        C++:
        @void sideBar::initializeSideBar()
        {
        QXmlQuery query1;
        QString name1;
        QString url1;
        QXmlQuery query2;
        QString name2;
        QString url2;
        QFile sidebarQuery("/Users/nick/Desktop/files for NovaBrowser/sidebarQuery.xq");

        sidebarQuery.open(QIODevice::ReadWrite);
        
        query1.setQuery(&sidebarQuery, QUrl::fromLocalFile(sidebarQuery.fileName()));
        query1.evaluateTo(&name1);
        
        createAppButton(name1);
        

        }
        @

        XQuery:
        @xquery version "1.0";

        doc("sidebarApps.xml")/sidebarapps/app[pos = 1]/name@

        XML:
        @<?xml version="1.0" encoding="UTF-8"?>

        <sidebarapps>
        <app>
        <name>Google Drive</name>
        <url></url>
        <pos>1</pos>
        </app>

        <app>
        <name>Gmail</name>
        <url></url>
        <pos>2</pos>
        </app>

        <app>
        <name>Google Docs</name>
        <url></url>
        <pos>3</pos>
        </app>

        <app>
        <name>Google Calendar</name>
        <url></url>
        <pos>4</pos>
        </app>

        <app>
        <name>Facebook</name>
        <url></url>
        <pos>5</pos>
        </app>

        <app>
        <name>Twitter</name>
        <url></url>
        <pos>6</pos>
        </app>
        </sidebarapps>@

        Ok so there you have it. It probably is something obvious (Im still a n00bie). Is it possible to do the file parsing in another thread and then send the results into the GUI thread?
        Thanks for your help!

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hpollak
          wrote on last edited by
          #4

          why do you not use signal and slot mechanism?

          see "QThread Basics":http://qt-project.org/doc/qt-5.0/qtcore/thread-basics.html

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nicky j
            wrote on last edited by
            #5

            why would I use signals and slots?

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hpollak
              wrote on last edited by
              #6

              for sending the results from the parserthread to the GUI

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nicky j
                wrote on last edited by
                #7

                So I would make a thread to parse the XML and another for the GUI. Once the parsing is complete, it would send the results to the GUI?
                How would that work? Could you give me a code example?

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  nicky j
                  wrote on last edited by
                  #8

                  So can I place an individual function in a QThread rather than the entire class? I would like to create a new thread, run the XML parsing function in it, then send the data to the GUI thread via signals and slots, and finally destroy the thread. Is that possible? how would I do it?

                  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