Results 1 to 4 of 4

Thread: Problem with operating of QTimer

  1. #1
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Problem with operating of QTimer

    Hi,
    I have a problem with QTimer.In my application there is a main window and two Pushbuttons on main window.If I click one button a QTimer *timer will starts calling one function for every 10ms.It is declared in .h file of mainwindow as public .If I click second Pushbutton dialog will opens.Here in the dialog class I want to stop the timer which was started in mainwindow class.The code i used is shown below.

    Qt Code:
    1. mainwin owin;
    2. owin.timer->stop();
    To copy to clipboard, switch view to plain text mode 

    I wrote this code in dialog constructor.But it showing some run time error as "Unhandled exception at 0x670df703 in lpsc-jul16th.exe: 0xC0000005: Access violation reading location 0x56530908." and "There is no source code available for the current location." when i click the second Pushbutton to open the dialog.
    So please help me to solve this problem.

    With Regards,
    Sudheer.
    Last edited by sudheer168; 8th October 2008 at 09:19.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with operating of QTimer

    You surely can't construct a new object and try to call its nonexisting members. You have to access the original object where you created the timer and stop it there. Better yet use signals and slots between both objects, it'll probably be much easier than trying to access the object manually.

  3. #3
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Problem with operating of QTimer

    Hi,
    Thanks for your quick reply . I once again posted my clear code what I want .

    mainwin.cpp
    Qt Code:
    1. #include "mainwin.h"
    2.  
    3. mainwin.h::lpsu_application(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. setupUi(this);
    7. QMainWindow::showMaximized();
    8.  
    9. }
    10. void mainwin.h::on_Pushbutton1_Button_clicked()
    11. {
    12. timer = new QTimer(this); // it is decleare in .h file as QTimer *timer as public
    13. connect(timer, SIGNAL(timeout()), this, SLOT(Averagedata()));
    14. timer->start(10);
    15. }
    16. void mainwin.h::on_Pushbutton2_Button_clicked()
    17. {
    18. channel dialog(this);
    19. dialog.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    channel.cpp
    Qt Code:
    1. #include "channel.h"
    2.  
    3. temperature_pane::temperature_pane(QWidget *parent)
    4. : QDialog(parent)
    5. {
    6. setupUi(this);
    7.  
    8. mainwin oman; // included "mainwin.h" in .h file of this class
    9. oman.timer->stop();
    10. }
    To copy to clipboard, switch view to plain text mode 

    So here i want to stop the timer started in mainwin.cpp in the channel.cpp.But if i click on Pushbutton2 the execution was stoping and showing some error which I posted in previous post.

    So please help me to solve the pronlem
    with Regards
    Sudheer.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with operating of QTimer

    As I said, your problem is strictly C++ related. In line #8 of the second snippet you provided you create a new object and try to reference it's "timer" member which at that point is uninitialized because you initialize it later in a method that is never called on that object. If you put a newspaper on a table in your house, you can't walk into any other existing house and expect the same newspaper lying on the table.

Similar Threads

  1. QTimer problem
    By rajeshs in forum Qt Programming
    Replies: 3
    Last Post: 13th September 2008, 15:33
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 13:48
  3. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 17:50
  4. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 09:13
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54

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.