Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. How to set QPoint variable as a global variable?
QtWS25 Last Chance

How to set QPoint variable as a global variable?

Scheduled Pinned Locked Moved Solved Qt in Education
qpointglobal vars
3 Posts 2 Posters 3.2k Views
  • 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 Offline
    B Offline
    beginMyCoding
    wrote on 2 Mar 2016, 19:38 last edited by
    #1

    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
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on 2 Mar 2016, 19:57 last edited by
      #2

      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 2 Mar 2016, 20:19
      2
      • C Carmoneer
        2 Mar 2016, 19:57

        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 Offline
        B Offline
        beginMyCoding
        wrote on 2 Mar 2016, 20:19 last edited by
        #3

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

        1 Reply Last reply
        1

        2/3

        2 Mar 2016, 19:57

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved