Results 1 to 4 of 4

Thread: Problem of QTimer with repeat statments

  1. #1

    Default Problem of QTimer with repeat statments

    Dear all QT Expert

    I make a program of using the QTimer class and I create a QTimer in the Constructor as follows and every time the timer start it show up 2 repeat statment as follows :

    system test 1
    system test 1

    system test 2
    system test 2

    It seems run 2 times every trigger with same slot. Is it some problems of my code or any statements missing to make this happen. Please help !!

    My code

    QTimer *sendtimer = new QTimer(this);
    connect(sendtimer, SIGNAL(timeout()), this, SLOT(testprog()));
    sendtimer->start(8000);


    void ConfigurationPage::testprog()
    {


    qDebug() << "system test " << loopcount++;

    return;

    }


    testdata = QString("system test %1").arg(loopcount);

    qDebug() << testdata <<"\n";

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Problem of QTimer with repeat statments

    your code is not quite clear (it is a collection of fragments);

    but it looks like you have 2 places that print such a line: one in the slot connected to timeout, another when printing the string testdata. So I would not be that surprised about getting 2 such lines...
    show us the real code, if that doesn't solve it.

  3. #3

    Default Re: Problem of QTimer with repeat statments

    thanks for your reply

    SInce I found that the problem due to I refer to this class in othe class by declaration


    in other class query

    Configuration cpage;


    testlist.append(cpage.roominfo);

    which will call the Configuration class constructor again which make the repetition

    Please advise how can I use other class variable without trigger the constructor

    sorry for I am newbie of the C++ program to ask those questions

    thx

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: Problem of QTimer with repeat statments

    you can try storing pointers instead.

    Qt Code:
    1. QList<X*> aList;
    2. aList << new X(...);
    To copy to clipboard, switch view to plain text mode 
    where X would be the class type you want to store.

    If you do that, you have to make sure that the heap-allocated objects will be deletetd (with delete) eventually.
    Alternatively, you can use smart pointers, like QSharedPointer

Similar Threads

  1. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 16:50
  2. QTimer and QSqlDatabase Problem
    By smtgra011 in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 16:37
  3. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 08:13
  4. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  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
  •  
Qt is a trademark of The Qt Company.