Results 1 to 6 of 6

Thread: how to set wait condition

  1. #1
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default how to set wait condition

    hi,

    i have some ballons which should come one by one with a time gap.so that i can get random character different as ballon text.how can i do that?

    please help me

    regards,
    hema

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to set wait condition

    I guess you mean tool tip by balloons. You could use QTimer to do so, start a QTimer, and in the slot connected to QTimer show the balloons as required.

    Qt Code:
    1. QTimer * timer = new QTimer(1000); // 1 second
    2. connect(timer, SIGNAL(timeout), this, SLOT(createBalloon));
    3. timer->start();
    4.  
    5. void createBalloon(void)
    6. {
    7. //create / show balloon.
    8. }
    To copy to clipboard, switch view to plain text mode 

    I hope, you know how to use signals and slots

  3. The following user says thank you to Santosh Reddy for this useful post:

    hema (25th July 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to set wait condition

    hi sir,
    thanks for ur reply.
    the solution giving error.
    main.cpp-------------where i call ballon.cpp
    Qt Code:
    1. #include<QtGui>
    2. #include"ballon.h"
    3. int main(int argc,char **argv)
    4. {
    5.  
    6. QApplication app(argc,argv);
    7. QString str[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    8. scene.setSceneRect(0,0,600,600);
    9. scene.addRect(0,10,600,30);
    10. scene.addText("After / Before",QFont("",18,QFont::Bold));
    11. scene.setBackgroundBrush(Qt::yellow);
    12. scene.setItemIndexMethod(QGraphicsScene::NoIndex);
    13. for(int i=1;i<=3;i++)
    14. {
    15. for(int j=1;j<=9;j++)
    16. {
    17. if(i*j<=26)
    18. {
    19. QTimer *interval=new QTimer(1000,this);
    20. QObject::connect(&interval,SIGNAL(timeout()),this,SLOT(createBallon()));
    21.  
    22. }
    23.  
    24. }
    25. }
    26.  
    27. QGraphicsView view(&scene);
    28. view.setRenderHint(QPainter::Antialiasing);
    29. view.setCacheMode(QGraphicsView::CacheBackground);
    30. //view.setMaximumSize(600,600);
    31. view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    32. view.show();
    33. QTimer timer;
    34. QObject::connect(&timer,SIGNAL(timeout()),&scene,SLOT(advance()));
    35. timer.start(1000);
    36. return app.exec();
    37. }
    38. void createBallon()
    39. {
    40. int random=qrand()%26;
    41. Ballon *ball=new Ballon(str[random]);
    42. ball->setPos(0+(j*60),550+(i*65));
    43. scene.addItem(ball);
    44.  
    45. }
    To copy to clipboard, switch view to plain text mode 

    ballon.cpp -----------------

    Qt Code:
    1. #include "ballon.h"
    2. #include<QFont>
    3. #include<QPainter>
    4. #include<QGraphicsItemAnimation>
    5. #include<QGraphicsScene>
    6. #include<QGraphicsSceneMouseEvent>
    7.  
    8. Ballon::Ballon(QString text): _mtext(text)
    9. {
    10. setFlag(QGraphicsItem::ItemIsMovable,TRUE);
    11.  
    12. }
    13. void Ballon::setText(QString text)
    14. {
    15. _mtext=text;
    16. }
    17. QString Ballon::getText()
    18. {
    19. return _mtext;
    20. }
    21. void Ballon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    22. {
    23. painter->setBrush(Qt::red);
    24. painter->drawEllipse(boundingRect());
    25. painter->drawText(boundingRect().center(),_mtext);
    26.  
    27. }
    28.  
    29. QRectF Ballon::boundingRect() const
    30. {
    31. return QRectF(0,0,40,60);
    32. }
    33. void Ballon::advance(int phase)
    34. {
    35. Q_UNUSED(phase);
    36. QList<QGraphicsItem*> items=scene()->items();
    37. foreach (QGraphicsItem *item, items) {
    38. QPointF point=item->pos();
    39. if(point.ry()<=40)
    40. item->setPos(point.rx(),point.ry());
    41. else
    42. item->moveBy(0,-2);
    43. }
    44. }
    45. void Ballon::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
    46. {
    47. QGraphicsItem *item=scene()->mouseGrabberItem();
    48. scene()->removeItem(item);
    49.  
    50. }
    To copy to clipboard, switch view to plain text mode 


    Error-----------invalid use of this in non member function
    how can i set time interval please how can i insert signal from main.cpp to ballon constructor

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to set wait condition

    Note my earlier reply
    Quote Originally Posted by Santosh Reddy
    I hope, you know how to use signals and slots
    You get an error because you don't know how to use signals & slots (Don't feel bad). I will try to explain a bit, you should be reading a good book or Qt Documentation at-least.

    Following points are what you missed
    - main() is a global function, it does not have a object instance of itself, so you cannot use this pointer in main() (it's basic C++, nothing to do with Qt), this is very reason you have an error.
    - A slot has to a member function of a class which is either directly or indirectly derived from a QObject, i.e SLOT cannot be a global function (which is a problem in you case)
    - You are creating 27 (3 x 9) timers, you should be creating only one timer, and each time the timer slot is called then create a balloon.

  6. #5
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to set wait condition

    sir,

    i know that 'this' can not be used in main function.

    my app is to produce 26 ballons with A-Z as text . ballon,GraphicsItem should be viewed in GraphicsScene with a time gap.

    how can i achieve this?

    i have to call ballon constuctor with random character as input in main.cpp.

    regards,
    hema

  7. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to set wait condition

    Ok, there are many ways, i just give one example to do so. Refer the sample example, I tried to create from your inputs, check it out
    Attached Files Attached Files

  8. The following user says thank you to Santosh Reddy for this useful post:

    hema (25th July 2011)

Similar Threads

  1. Using an If condition in a QML delegate?
    By technoViking in forum Qt Quick
    Replies: 8
    Last Post: 25th August 2011, 05:26
  2. don`t work Condition...
    By Resager in forum Newbie
    Replies: 1
    Last Post: 6th May 2011, 18:18
  3. QFileDialog custom acceptance condition
    By akos.maroy in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2011, 12:35
  4. How can i terminate a delay / wait condition
    By asinghma in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2011, 14:41
  5. Sleep condition in QT
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2008, 12:07

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.