Results 1 to 7 of 7

Thread: QThread problem

  1. #1
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Thumbs up QThread problem

    Hello Everyone
    I have a little problem and hope you will help me
    My problem is that I wana start my process in the thread the reason is that I m moving a widget over a widget on timeout event of QTimer but problem is this whenevr there start more than one process ,then the movement of widget start jerk so stop all these I wana move my widget using QThread .................
    But I have no idea how do it ?????????
    Please suggest me some hints

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QThread problem

    1) There is no need to execute a process in a thread. It is a different process, it doesn't block the current process unless you use blocking waitXXX() methods.
    2) Touching GUI in a worker thread is prohibited.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QThread problem

    Thanx for reply JPN ..........
    But my problem is still remain.......
    I just wana stop jerking or flikering of widget when there exist more than one process,,,,,,
    what I do for it
    Last edited by MrShahi; 10th July 2008 at 06:51.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QThread problem

    Could you provide a bit more details what do you actually do and how you do it?
    J-P Nurmi

  5. #5
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QThread problem

    yes this my move.h file
    Qt Code:
    1. #ifndef MOVE_H
    2. #define MOVE_H
    3. #include<QWidget>
    4. #include"ui_move.h"
    5. class Move : public QWidget,public Ui_Form
    6. {
    7.  
    8. Q_OBJECT
    9.  
    10. public:
    11. Move(QWidget *parent=0);
    12. int x;;
    13. int y;
    14. int width;
    15. public slots:
    16.  
    17. void moveWidget();
    18.  
    19. };
    20. #endif
    To copy to clipboard, switch view to plain text mode 
    and this my move.cpp file



    Qt Code:
    1. #include"move.h"
    2. #include "ui_move.h"
    3. #include<QDebug>
    4. #include<QTimer>
    5. #include<QtGui>
    6. #include<QPoint>
    7. Move::Move(QWidget *parent) : QWidget(parent)
    8. {
    9.  
    10. setupUi(this);
    11. x=950;
    12. y=10;
    13. int locx=1024*0/100;
    14. int locy=768*80/100;
    15. int w=1024*100/100;
    16.  
    17. int h=768*20/100;
    18. QString si("Sonu Shahi is great Enjoy ");
    19.  
    20.  
    21. this->setGeometry(locx,locy,w,h);
    22.  
    23. QLabel *label=new QLabel( si,widget);
    24. label->setTextFormat (Qt::RichText );
    25. QFont font("Helvetica", 72, QFont::Bold);
    26. label->setFont(font);
    27.  
    28. QFontMetrics fm(font);
    29. width = fm.width(si);
    30. int pixelsHigh = fm.height();
    31. qDebug()<<"size of si"<<si.size ()<<"width of font"<<width<<"hight"<<pixelsHigh;
    32. label->show();
    33. widget->setGeometry(950,55,width,pixelsHigh);
    34. QTimer *timer = new QTimer;
    35. connect(timer,SIGNAL(timeout()),this,SLOT(moveWidget()));
    36. timer->start(10);
    37. QPalette palette;
    38.  
    39. QBrush brush(Qt::red,Qt::SolidPattern);
    40.  
    41. palette.setBrush(QPalette::Active, QPalette::Window, brush);
    42. this->setPalette(palette);
    43. label->setPalette(palette);
    44. widget->setPalette(palette);
    45. /**********************/
    46. QPalette palette1;
    47.  
    48. QBrush brush1(Qt::yellow,Qt::SolidPattern);
    49.  
    50. palette1.setBrush(QPalette::Active, QPalette::WindowText, brush1);
    51. //this->setPalette(palette);
    52. label->setPalette(palette1);
    53. //widget->setPalette(palette);
    54. /*******************/
    55.  
    56. }
    57. void Move::moveWidget()
    58. {
    59. QPoint m=widget->pos();
    60. if(x<=-width)
    61. x=950;
    62.  
    63. x=x-1;
    64.  
    65.  
    66. widget->move(x,y);
    67.  
    68. }
    To copy to clipboard, switch view to plain text mode 


    I simply call this class in main .cpp and play it ......
    and output is as good as I want .........
    But whenever I embed this code into my movie player code where different movie are simultaniousely play within multiple widget this start jerking ...........thts why I m searching a logic or hint through which I stop jerking ...............
    I think its enough for you ............................
    Last edited by jpn; 10th July 2008 at 07:10. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QThread problem

    Can anyone tell me how can smoothly play my scrollor...................

  7. #7
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QThread problem

    Hello guys , I have solved my problems
    ...................
    but again there is little bit problem ...................
    i.e the widget which is moving , sometimes becomes jerky and after sometime it scroll smoothly ...............why I don't know ????????
    If any one can help me I'll appericiate him..........
    Thanks

Similar Threads

  1. QThread and PostgreSQL - a problem
    By Lesiok in forum Qt Programming
    Replies: 12
    Last Post: 9th April 2008, 09:07
  2. Problem with QTcpSocket in QThread
    By Raistlin in forum Qt Programming
    Replies: 8
    Last Post: 6th October 2007, 12:23
  3. QThread and QProcess problem
    By codebehind in forum Qt Programming
    Replies: 13
    Last Post: 7th August 2007, 08:11
  4. Replies: 3
    Last Post: 15th April 2007, 19:16
  5. Qthread n QTimer Problem
    By quickNitin in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2006, 14:12

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.