Results 1 to 6 of 6

Thread: change progress bar value from a thread

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2016
    Posts
    3
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default change progress bar value from a thread

    hi every one.
    i write this cod.
    how i can change progress bar value from my thread?
    signal and slots?
    how use signal and slots for this program??


    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include <QThread>
    4. #include <QDebug>
    5. #include <mainwindow.h>
    6.  
    7.  
    8.  
    9.  
    10. int i ;
    11.  
    12.  
    13.  
    14.  
    15.  
    16.  
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23.  
    24. class Thread : public QThread
    25. {
    26. private:
    27. void run()
    28. {
    29. for(i;i<=100;i++)
    30. QThread::sleep(1);
    31.  
    32. }
    33.  
    34. };
    35.  
    36.  
    37.  
    38.  
    39.  
    40. int main(int argc, char *argv[])
    41. {
    42. QApplication a(argc, argv);
    43. MainWindow w;
    44. w.show();
    45.  
    46.  
    47.  
    48. //Thread();
    49.  
    50.  
    51.  
    52.  
    53.  
    54. qDebug()<<"From main thread: "<<QThread::currentThreadId();
    55.  
    56. Thread t;
    57. QObject::connect(&t, SIGNAL(finished()), &a, SLOT(quit()));
    58.  
    59. t.start();
    60.  
    61.  
    62. //--------------------
    63.  
    64.  
    65. //---------------------------------------
    66.  
    67.  
    68.  
    69.  
    70.  
    71.  
    72.  
    73.  
    74. return a.exec();
    75.  
    76. }
    To copy to clipboard, switch view to plain text mode 




    mainwindow.cpp:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QApplication>
    4.  
    5.  
    6.  
    7.  
    8.  
    9. extern int i;
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16. MainWindow::MainWindow(QWidget *parent) :
    17. QMainWindow(parent),
    18. ui(new Ui::MainWindow)
    19. {
    20. ui->setupUi(this);
    21.  
    22.  
    23. }
    24.  
    25. MainWindow::~MainWindow()
    26. {
    27. delete ui;
    28.  
    29. }
    30.  
    31. void MainWindow::on_pushButton_pressed()
    32. {
    33.  
    34. // ui->progressBar->setValue(i);
    35.  
    36.  
    37. //ui->progressBar->update();
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 29th November 2016 at 12:21. Reason: changed [qtclass] to [code]

Similar Threads

  1. Update progress bar in another thread
    By qt_developer in forum Qt Programming
    Replies: 8
    Last Post: 19th June 2012, 18:41
  2. set progress bar values inside a thread
    By ruben.rodrigues in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2011, 14:55
  3. Thread updates progress bar
    By GianMarco in forum Qt Programming
    Replies: 7
    Last Post: 12th October 2009, 13:29
  4. busy progress bar without thread ?
    By npc in forum Newbie
    Replies: 34
    Last Post: 23rd July 2009, 09:29
  5. Display progress on another thread
    By radu_d in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2007, 08:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.