Results 1 to 4 of 4

Thread: QMainWindow Dragging is suspending QTimer

  1. #1
    Join Date
    Oct 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QMainWindow Dragging is suspending QTimer

    Hi.
    I have a class that inherits QMainWindow.And that class has a QTimer as an attribute.Qtimer starts at construction.When I do a mouse press or a drag event on that QMainWindow or a child widget of that mainwindow the timer is suspending.That suspending suspends my drawing in a QGraphicview.I understand the stopping of drawing at dragging or etc..But if timer stops,my GraphicItem falls behind the position which GraphicItem must be there at the time.
    So does anybody know a way how I can prevent the application from freezing of QTimer?
    Regards..

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow Dragging is suspending QTimer

    Please share the relevant code

  3. #3
    Join Date
    Oct 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Wink Re: QMainWindow Dragging is suspending QTimer

    //mainclass.h
    #include <QMainWindow>
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QGraphicsLineItem>
    #include <qtimer.h>
    #include "ui_mainclass.h"

    class MainClass : public QMainWindow
    {
    Q_OBJECT

    public:
    MainClass(QWidget *parent = 0);
    ~MainClass();
    QTimer timer;
    QGraphicsScene scene;
    QGraphicsView *view;
    QGraphicsLineItem *line;
    public slots:
    void moveLine();
    void openWindow();

    private:
    Ui::MainClassClass ui;
    };

    //mainclass.cpp
    #include "mainclass.h"
    #include "window.h"
    #include <QPen>



    MainClass::MainClass(QWidget *parent)
    : QMainWindow(parent)
    {
    QPen pu(Qt::red);
    pu.setCapStyle(Qt::RoundCap);
    pu.setJoinStyle(Qt::RoundJoin);
    pu.setWidth(7);
    ui.setupUi(this);
    line=new QGraphicsLineItem(100,100,200,100);
    line->setPen(pu);
    line->setFlag(QGraphicsItem::ItemIsMovable);
    scene.addItem(line);
    //QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
    QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(moveLine()));
    timer.start(30);
    scene.setSceneRect(0, 0,80000, 600);
    view=new QGraphicsView(&scene,this);
    view->setGeometry(0,50,800,620);
    connect(ui.actionOpen,SIGNAL(triggered()),this,SLO T(openWindow()));

    for(int i=0;i<200;i++)
    {
    pu.setColor(Qt::green);
    pu.setWidth(3);
    QGraphicsLineItem *templine=new QGraphicsLineItem(30*i,110,30*i,120);
    QGraphicsSimpleTextItem *text=new QGraphicsSimpleTextItem(QString().setNum(30*i));
    text->setPos(30*i,130);
    templine->setPen(pu);
    scene.addItem(templine);
    scene.addItem(text);
    }


    }

    void MainClass::moveLine()
    {
    line->moveBy(1,0);
    view->centerOn(line);
    }
    MainClass::~MainClass()
    {

    }
    void MainClass:penWindow()
    {
    mywindow* mywind=new mywindow();
    mywind->show();
    }

    //main.cpp

    #include <qapplication.h>
    #include "mainclass.h"
    #include <stdlib.h>
    int main(int argc, char** argv)
    {
    QApplication app(argc,argv);
    MainClass m;
    m.resize(m.sizeHint());
    m.setCaption("QTimer");
    m.setGeometry(40,40,810,610);
    m.show();
    QObject::connect( qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()) );
    return app.exec();
    }
    (mywindow is a simple widget).
    Here is an example that's code is similar with my application.But I see it is working.In my application I use a code like above.But in my code that isn't working.my code is very long to put it here.
    My application is a simulator management screen so,it must work sychronously with simulator engine.If my timer stops or suspend for any resason the system gives error.
    So I'll be waiting for any reply.
    Regards.

  4. #4
    Join Date
    Oct 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMainWindow Dragging is suspending QTimer

    I found the problem.If time out span of the timer is under 15 miliseconds,the widget is suspending the timer during the dragging or etc.In the example above it is 30 ms,but in my application it was 10 ms,now I've rised it up to 20 ms it is working well.
    Regards.

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.