Home

OFF-SOFT.net

OFF-SOFT.net

This site is support & information site of WEB,and Software. This site might help you that create software or Web Site…perhaps?[:]

Qt(B4) How to show Marquee(barbar-pole) with Qt

Published on| August 27th, 2009 | No Comment.
Summary:
This time, Qt marquee explains the progress bar to show how easily.
and marquee, WindowsXP from the startup screen after the progress bar, rather than to build up, and the show flowing now is to show progress.

This marquee (see propaganda) and the colors that we have referred.
indeterminate (in the effective running I do not know how much), barber-pole (barber's pole), spinning bar (a bar that spins round and round) and so on.
(Web on, barber-pole like a major but, here, marquee Make a uniform. () Is a literal translation in Japanese. I tried to describe what I felt better somehow, I'll understand. )

Came to the Windows API that is compatible with, it is not too old.

This time, Qt uses a sample that is provided in the marquee we'll see.



Immediately, let's use the sample display
The sample used here is a sample of the progress bar.
Usually located in the directory below.
% Qt installation directory% \ qt \ examples \ qtconcurrent \ progressdialog
The following is the main.cpp.
[main.cpp]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using namespace QtConcurrent;
 
const int iterations = 20;
 
void spin(int &iteration)
{
    const int work = 1000 * 1000 * 40;
    volatile int v = 0;
    for (int j = 0; j < work; ++j)
        ++v;
 
    qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId();
}
 
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
 
    // Prepare the vector.
    QVector<int> vector;
    for (int i = 0; i < iterations; ++i)
        vector.append(i);
 
    // Create a progress dialog.
    QProgressDialog dialog;
    dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount()));
 
    // Create a QFutureWatcher and conncect signals and slots.
    QFutureWatcher<void> futureWatcher;
    QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
    QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
    QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int)));
    QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));
 
    // Start the computation.
    futureWatcher.setFuture(QtConcurrent::map(vector, spin));
 
    // Display the dialog and start the event loop.
    dialog.exec();
 
    futureWatcher.waitForFinished();
 
    // Query the future to check if was canceled.
    qDebug() << "Canceled?" << futureWatcher.future().isCanceled();
}

QFutureWatcher contains a description of the class so little that is complex, doing that is simple. QFutureWatcher with class, causing the thread, QProgressDialog class by calling setValue to 20 times in a row.

5 from the first line, spin functions are called. This function is called 20 times. Dzutsude times that one is a demonstration of the long processing functions. After calling this function, QFutureWatcher progressValueChanged class and causing a signal.
progressValueChanged received signals, QProgressDialog the setValue progress bar is displayed in the switch mechanism.

The following screen appears when you run, the progress bar reaches 100% and then to automatically terminate.


Switch Qt to display a progress bar in marquee is easy.
Main.cpp 32 just above the following changes to the line.
[main.cpp]
1
2
//    QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int)));
    dialog.setRange(0, 0);

Let's run it.


It is easy. The range of 0 and would progress to switch to fixed marquee display.

This marquee display, Windows2000 You can view as well. (95 systems do not know. )
In addition, the document is likely since there is no notation, and possibly, may not be a formal response, on the understanding, please do not use.
(At least at work 4.5.1,4.5.2 was the same. )

Once you know, I do wonder if the author is to arrive in this way, very, took a long time.
A little, but this article, I hope to help you if.

(loadposition QTAmazon)

Comments

Leave a Reply







  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ