Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:51:02+00:00 2026-06-13T12:51:02+00:00

I’m trying to implement a basic qtimer in a qgraphicsview but can’t seem to

  • 0

I’m trying to implement a basic qtimer in a qgraphicsview but can’t seem to get it working.

Here’s my main.cpp code:

int main(int argc, char * argv[]) {


    QApplication app(argc, argv);//should stay on the stack

    QGraphicsScene * scene = new QGraphicsScene();//this is the scene -- the canvas that holds everything!

    // a view just adds stuff to the scene in that view port

    QGraphicsView * view = new Game(scene);//create a new view

    return app.exec();
}

And here is the view header … note the qtimer and advance function

class View: public QGraphicsView {//inherits qwidget -- so we can make it full screen there

    Q_OBJECT

    public:
        View(QGraphicsScene * _scene);//this is responsible for setting up the screen and instantiating several elements
        ~View();

    protected://variables
        QGraphicsScene * scene;
        QTimer * timer;


    protected://functions

        int const int_height();//converts qreal to an int
        int const int_width();

        qreal const height();// 
        qreal const width();//this is the actual qreal floating point number 

        virtual void paintEvent(QPaintEvent * event) {};
        void timerEvent(QTimerEvent * event) {cout << "HELLO << ads" << endl;};
        virtual void keyPressEvent(QKeyEvent * event) {};
        virtual void update() = 0;


        void advance() { cout << "HELLO WORLD" << endl;}        
    private:
        qreal _height;
        qreal _width;

};

And finally, my view implementation constructor:

View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {


    scene = _scene;//set the scene which is the parent over this 


    this->showMaximized();

    QRectF geometry = this->contentsRect();

    _height = geometry.height();
    _width = geometry.width();

    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    scene->setSceneRect(0, 0, this->int_width(), this->int_height());
    // this->centerOn(qreal(0), qreal(0));

    this->setGeometry(0, 0, _width, _height);
    this->setFixedSize(_width, _height);


    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), scene, SLOT(advance()));
    timer->start(1000);
    timer->setInterval(100);



}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:51:03+00:00Added an answer on June 13, 2026 at 12:51 pm

    You need to declare your advance() function as a slot in the header file. Otherwise Qt does not know that this particular function is a slot:

    protected slots:
        void advance() { cout << "HELLO WORLD" << endl; } 
    

    Then, you are connecting the timeout signal to the advance() slot in the scene – but you declared it in your view. As you are currently in the view, you can use the this pointer to connect the signal to your view. Change your connect like this:

    connect(timer, SIGNAL(timeout()), this, SLOT(advance())); 
    //                                ^^^^
    

    [Edit] As a side node: You are creating a QGraphicsView subclass of type Game, but you showed the source code of View. This might be irrelevant if Game inherits from View though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.