QProgressBar - signal if it`s full, possible or manual coding?



  • Hello again :)
    Ive noticed a design flaw in my daemon qt hybrid, in which, crypting large files takes time and user does not know what is going on, so Ive embeded a progress bar, which took me an hour to reinvent how to work from the POSIX thread which is separate from Qt.
    Those lines of code from Qt GUI:
    [CODE]
    ...
    SimpleGUI* SimpleGUI::emulatedGlobal=NULL;
    ...
    void SimpleGUI::callDirwalk() {
    //thread main()
    pthread_t t;
    int res = pthread_create(&t, NULL, doSomething2, NULL);

    }
    ...
    void* doSomething2(void* a) {
    writeToFile("Called init_dirWalk() on a separate thread\n", LOGOTHER, "a+");
    init_dirWalk(SimpleGUI::emulatedGlobal, SimpleGUI::argc, SimpleGUI::argv);

    }
    [/CODE]
    which many of you will blame me for doing such C-ish things like static global var, but Ive found out there is no way to report to daemon which is separate and can work without the GUI, to report and communicate with the UI. So basically Ive rewriten my foreach loop of the custom linked list to this:
    [CODE]
    /* for qt applications /
    void forEachVer2(SimpleGUI
    spl, DList* list, _doSomething doit) {
    LNode* h = list->head;
    spl->getProgressBar()->setRange(0, _index);
    int i=0;
    while ( h ) {
    doit(h);
    h = h->next;
    spl->getProgressBar()->setValue(i++);
    }
    }
    [/CODE]
    where _index is global static var for DList.c, which helds the No of elements in list, so actually I got the desired result, on each iteration the progress fills a little. Here is what it looks like:
    https://www.flickr.com/photos/heatblazer/15206624198/
    So my question is - is there a signal to report if the bar is full? And can I set the text of the file being worked on? And all this things should happen from the forEachVer2 I guess, since, GUI lives just when it time comes from the daemon - then it visualizes the operations, then dies. So actually clicking cancel, even that the walk dir and lists are working on separate thread, actually kills the process, since a NULL reference is trying to be accessed from the forEachVer2() loop, I know this is ugly stuff, I`ll polish it when I got the idea how to make it to fit.


  • Moderators

    Hi,

    Have a look at the "QProgressBar documentation":http://qt-project.org/doc/qt-5/QProgressBar.html

    [quote]is there a signal to report if the bar is full?[/quote] The is no specific signal that is only emitted when the bar is full. However, the valueChanged() signal is emitted every time the bar changes value -- this includes the point when the bar becomes full.

    You can check the value of the valueChanged() signal, and run a special function when it reaches 100%.

    [quote]And can I set the text of the file being worked on?[/quote]Do you mean show the text inside the progress bar?

    See the format property in the QProgressBar documentation.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.