Results 1 to 9 of 9

Thread: progressbar generate by the label value

  1. #1
    Join Date
    Dec 2016
    Posts
    10
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    3

    Default progressbar generate by the label value

    guys i need the progress bar to vary the values...(i.e)i have a label which shows the random numbers. i need the signal from the label to the progressbar...
    each time the number changes the progress bar must change the value..

    help me with a code..
    Last edited by CAFFRY; 28th December 2016 at 12:07.

  2. #2
    Join Date
    Dec 2016
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: basic Tic Tac Toe game

    go to "edit signals/slots" and connect your label to the progress bar by clicking on the label and dragging the cursor to the progress bar. then choose "ValueChanged(int)" and "SetValue(int)" then click OK.

    I don't know much of Qt but this should work.
    Last edited by daud anjum; 29th December 2016 at 13:32.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: basic Tic Tac Toe game

    I don't know much of Qt but this should work
    No, it won't work. QLabel does not have a signal called "ValueChanged()" (and QProgressBar doesn't have a slot named "SetValue()", but it -does- have one named "setValue()").

    each time the number changes the progress bar must change the value.
    How are you setting the number as the text for the label? Using a signal emitted by the part of your program that generates the "random numbers"? If so, then if the signal is sending an "int" argument, simply connect this signal to the progress bar's setValue() slot. If your signal sends a QString, then you can implement your own slot that converts the string into a number (QString::toInt() or QString::toLong()) and then calls setValue() directly on the progress bar instance.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. The following user says thank you to d_stranz for this useful post:

    CAFFRY (30th December 2016)

  5. #4
    Join Date
    Dec 2016
    Posts
    10
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: basic Tic Tac Toe game

    this is my random code...


    srand ( time(NULL));
    int randnumber = rand() %100 + 1;

    for(int i=0;i>=100;i++)
    {
    i = qrand();
    }
    QString str;
    str.append(QString("%1").arg(randnumber));
    ui->percentage->setText(str + "%");
    if(randnumber<0)
    {
    QMessageBox::about(this,"error","runagain");
    }

    i need this to connect with the progressbar...
    it would me nice if u send me the code for that connection

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: basic Tic Tac Toe game

    for(int i=0;i>=100;i++)
    {
    i = qrand();
    }
    What the heck is this code supposed to do? It's nonsense, and in any case you shouldn't change the value of the loop iterator (i) inside the loop.

    i need this to connect with the progressbar...
    So how hard is that? You have an int random number, QProgressBar::setValue() is a method that takes an int argument, so if you have a UI widget named "progress" or something like that... You figured out how to set the text on the label, you should be able to figure out how to set the value on the progress bar.

    if(randnumber<0)
    Integers returned by the rand() function are always between 0 and RAND_MAX, so this statement will never be true. And your random numbers will always be between 1 and 100 because of the modulus operation (%) you do on the value returned by rand().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #6
    Join Date
    Dec 2016
    Posts
    10
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: basic Tic Tac Toe game

    can u write me a code for that, for the connection between the progressbar and the label value.

    and use the random code which i used ...plzzz..
    and thanks for the rply

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: basic Tic Tac Toe game

    Quote Originally Posted by CAFFRY View Post
    can u write me a code for that, for the connection between the progressbar and the label value.
    You don't need a connection, you can call the progress bar's setValue() just like you call the label's setText().

    Cheers,
    _

  9. #8
    Join Date
    Dec 2016
    Posts
    10
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: progressbar generate by the label value

    its not working

  10. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: progressbar generate by the label value

    its not working
    That doesn't tell us much. Post your latest code and we will take a look.

    By the way, this forum is not here to write your code for you. Everyone here is willing to help, but only if you try first and get stuck. We expect you to read the Qt documentation, look at the Qt tutorial and example programs, and try to solve problems yourself first. There are plenty of places in the Qt examples where basic widgets like QProgressBar and QLabel are used. If you study the examples, you might find how to do exactly what you need.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. How can I have a Progressbar with movement
    By roseicollis in forum Qt Programming
    Replies: 9
    Last Post: 9th January 2015, 16:05
  2. Maximum value of ProgressBar
    By jesse_mark in forum Newbie
    Replies: 4
    Last Post: 10th January 2013, 14:27
  3. Confused with progressbar
    By hakermania in forum Newbie
    Replies: 2
    Last Post: 23rd January 2011, 10:47
  4. Indefinite ProgressBar
    By csvivek in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 11:02
  5. Progressbar problem
    By thae in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 11:48

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
  •  
Qt is a trademark of The Qt Company.