I want to show the percentage of day elapsed using the progress bar in Qt,
for example, if its 12pm it should show 12/24*100=50 on the progress bar.
Please help!
Create a QTimer which calls slot update() every n minutes/hours:
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000 * 60 * 60); // call update slot every hour
This slot then updates the value of the progressbar:
QDateTime dateTime = QDateTime::currentDateTime();
progressBar->setValue(dateTime.time().hour()/24*100);
Related
I have Problem when i activate QTimer To Show A clock inside a Qlabel, my small software will use around 25 to 40 % of CPU Power (I3 4160) so how to solve it to take less hardware resources?
QTimer *timer1 = new QTimer(this);
connect(timer1,SIGNAL(timeout()),this,SLOT(showtime()));
timer1->start();
and this is my showtime() function
void Findlistrecord::showtime(){
QTime time = QTime::currentTime();
QString time_totext = time.toString("hh : mm : ss");
ui->timelabel->setText(time_totext);
}
As I see you didn't set an interval for you timer, so your timer will trigger as soon as it can. If you want to show the time with seconds accuracy I recommend that to use interval of 1000ms to reduce the process overhead.
timer1->start(1000);
in qt, I want to connect the current time with the timeEdit so when I launch the application, the time progresses.
I wrote this:
QDate myD = iDate->currentDate();
QTime myT = iTime->currentTime();
ui->dateEdit->setDate(myD);
ui->timeEdit->setTime(myT);
connect (dte, SIGNAL(getDate(myD)), ui->dateEdit, SLOT(setDate(myD)));
connect(dte, &QTimeEdit::timeChanged, ui->timeEdit,&QTimeEdit::setTime);
NB: QDateTimeEdit* dte = new QDateTimeEdit; declared in the .h file.
when I launch the app, the time is still freezing
There is nothing in the example code that is running to update the time. I would think you would need to start a 1 second timer and every timeout you update the QDateTimeEdit with the current QDateTime::currentDateTime.
Something like this:
QTimer* updatetimer = new QTimer();
connect(updatetimer, &QTimer::timeout, this, &UiClass::UpdateTimerTimeout)
updateTimer->start(1000);
UpdateTimerTimeout {
ui->dateEdit->setDate(QDateTime::currentDateTime().date());
ui->timeEdit->setTime(QDateTime::currentDateTime().time());
}
Something like that should do what you want.
I am trying to make two timers using QLCDNumber. These timers will be generated as a part of my status bar, in a dll. I have two LCDNumber displays. lcdNumber1 will start at a specified time (e.g. 12:00:00). lcdNumber2 will start at 0 (e.g. 00:00:00).
How am I able to create a timer for lcdNumber2 and let it to start ticking?
How can I add lcdNumber2's timer to lcdNumber1? Or can I create a timer for lcdNumber1 to start ticking from the specified time?
Could anyone please help?
QLCDNumber *lcdNumber1 = new QLCDNumber;
lcdNumber1->setNumDigits(8);
lcdNumber1->display(12:00:00);
statusBar->addWidget(lcdNumber1);
QLCDNumber *lcdNumber2 = new QLCDNumber;
lcdNumber2->setNumDigits(8);
lcdNumber2->display(00:00:00);
statusBar->addWidget(lcdNumber2);
Inherit QLCDNumber adding variable time to hold current time and another slot tick()
QLCDNumber_my::tick(){
time++;
this->display(time);
}
and then
QLCDNumber_my *lcdNumber1 = new QLCDNumber_my;
lcdNumber1->setNumDigits(8);
lcdNumber1->display(12:00:00);
statusBar->addWidget(lcdNumber1);
QTimer *timer = new QTimer(this);
timer->start(1000);
connect(timer, SIGNAL(timeout()), lcdNumber1, SLOT(tick()));
QLCDNumber is simple displaying widget, it cannot run, to produce time change you need to use sepatare timer (QTimer).
I want to make a program where I take each line of QPlainTextEdit and send it to a WebView which will load those urls. I don't need to check the URL's because the system makes it like that
http://someurl.com/ + each line of the QPlainTextEdit
I have few ideas which I don't know how to use:
Use a foreach loop which will make its self wait 5 seconds to loop again
Make a QTimer to wait like 5 seconds and tick with an integer and when the integer hits the number of lines it will stop
And all of that will be done on every 4 hours by waiting with another timer.
First of all you need the contents of the QPlainTextEdit. Get them and split them using the new line separator to get a list of QStrings each representing a line.
QString plainTextEditContents = ui->plainTextEdit->toPlainText()
QStringList lines = plainTextEditContents.split("\n");
The easiest way to process the lines is to use a QTimer and store somewhere the current index in the list.
// Start the timer
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(processLine()));
timer->start(5000);
Now the slot is called whenever the timer is triggered. It just gets the current line and you do it whatever you want.
void processLine(){
// This is the current index in the string list. If we have reached the end
// then we stop the timer.
currentIndex ++;
if (currentIndex == lines.count())
{
timer.stop();
currentIndex = 0;
return;
}
QString currentLine = lines[currentIndex];
doSomethingWithTheLine(currentLine);
}
Similarly do the same with the 4h timer.
I'm trying to make an app using Kinect (OpenNI), processing the image (OpenCV) with a GUI.
I tested de OpenNI+OpenCV and OpenCV+Qt
Normally when we use OpenCV+Qt we can make a QWidget to show the content of the camera (VideoCapture) .. Capture a frame and update this querying for new frames to device.
With OpenNI and OpenCV i see examples using a for cycle to pull data from Kinect Sensors (image, depth) , but i don't know how to make this pulling routing mora straightforward. I mean, similar to the OpenCV frame querying.
The idea is embed in a QWidget the images captured from Kinect. The QWidget will have (for now) 2 buttons "Start Kinect" and "Quit" ..and below the Painting section to show the data captured.
Any thoughs?
You can try the QTimer class to query the kinect at fixed time intervals. In my application I use the code below.
void UpperBodyGestures::refreshUsingTimer()
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(MainEventFunction()));
timer->start(30);
}
void UpperBodyGestures::on_pushButton_Kinect_clicked()
{
InitKinect();
ui.pushButton_Kinect->setEnabled(false);
}
// modify the main function to call refreshUsingTimer function
UpperBodyGestures w;
w.show();
w.refreshUsingTimer();
return a.exec();
Then to query the frame you can use the label widget. I'm posting an example code below:
// Query the depth data from Openni
const XnDepthPixel* pDepth = depthMD.Data();
// Convert it to opencv for manipulation etc
cv::Mat DepthBuf(480,640,CV_16UC1,(unsigned char*)g_Depth);
// Normalize Depth image to 0-255 range (cant remember max range number so assuming it as 10k)
DepthBuf = DepthBuf / 10000 *255;
DepthBuf.convertTo(DepthBuf,CV_8UC1);
// Convert opencv image to a Qimage object
QImage qimage((const unsigned char*)DepthBuf.data, DepthBuf.size().width, DepthBuf.size().height, DepthBuf.step, QImage::Format_RGB888);
// Display the Qimage in the defined mylabel object
ui.myLabel->setPixmap(pixmap.fromImage(qimage,0).scaled(QSize(300,300), Qt::KeepAspectRatio, Qt::FastTransformation));