Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to set QPoint variable as a global variable?

    Qt in Education
    qpoint global vars
    2
    3
    2868
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      beginMyCoding last edited by

      I want to set a QPoint variable as a global variable such that it can be accessible and changeable from 3 .cpp source files.

      I tried creating a new c++ class named globals as shown below

      globals.h

      #ifndef GLOBALS_H
      #define GLOBALS_H
      //#include <QPoint>
      
          extern QPoint firstPoint , secondPoint;
      
      #endif // GLOBALS_H
      

      globals.cpp

      #include "globals.h"
      #include <QPoint>
      
          QPoint firstPoint = 0;  //(0,0);
          QPoint secondPoint = 100;  //(10,10);
      

      if i include #include<QPoint> in globals.h
      this is the error

      conversion from 'int' to non-scalar type 'QPoint' requested
      

      if i do not include #include<QPoint> in globals.h
      error is

      QPoint does not name a type
      

      Does anyone know whats wrong in this and how to add a global variable in any other method?

      1 Reply Last reply Reply Quote 0
      • C
        Carmoneer last edited by

        This may help:

        http://stackoverflow.com/questions/18513332/c-qt-how-to-declare-and-initialize-a-global-array-of-objects

        Essentially, you don't want the definition to be defined as 'int' zero. Instead:

        QPoint firstPoint = QPoint(0,0,);

        Hope this helps.

        B 1 Reply Last reply Reply Quote 2
        • B
          beginMyCoding @Carmoneer last edited by

          @Carmoneer Thats the perfect solution
          Thanks a lot... :)

          1 Reply Last reply Reply Quote 1
          • First post
            Last post