Access the static variable...

Hello

I need a static variable which holds a QMap, for this example I'll use QMap.

I created fresh new project and I changed in applicationui.cpp:

...ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
{
....

    initDatabase( 1 );
    initDatabase( 2 );
    initDatabase( 3 );
    initDatabase( 4 );
}

bool ApplicationUI::initDatabase( int index )
{
    QString database = QString( "Db%1" ).arg( index );
    QString value = QString( "data/db%1.sqlite" ).arg( index );

    ApplicationUI::m_databases[database] = value; // undefined reference to `ApplicationUI::m_databases'

    return true;
}

ApplicationUI::~ApplicationUI()
{
    if( ApplicationUI::m_databases.count() ) // undefined reference to `ApplicationUI::m_databases'
    {
        foreach( const QString &key, ApplicationUI::m_databases.keys() ) // undefined reference to `ApplicationUI::m_databases'
        {
            QString db = ApplicationUI::m_databases[key]; // undefined reference to `ApplicationUI::m_databases'

            qDebug() << "Closing [" << db << "]";
        }
    }
}

and in applicationui.hpp:

...

class ApplicationUI : public QObject
{
    Q_OBJECT
public:
    ApplicationUI(bb::cascades::Application *app);
    ~ApplicationUI();

    static QMap m_databases;
    bool initDatabase( int index );
...
};

#endif /* ApplicationUI_HPP_ */

As you can see commented in the code above, I get error:
no reference to 'ApplicationUI::m_databases' applicationui.cpp

I thought to access static variables that ApplicationUI::m_databases would work.

Can you please guide me here.

Kind regards

Andy

Hello! That's what I saw:

(1) #include is present in the header file?

' (2) ' void ' is the syntax error:

void MyClass::~MyClass()

3)

static QMap variable;

is a declaration, you also need to create the variable in the .cpp file. Add to the .cpp:

QMap MyClass::variable;

4)

MyClass::variable["one"] = "value One"; // doesn't work...

"MyClass:" is not necessary. ['a'] variable should work too.

UPD: this compiles (I replaced QMap QString with std::map with std::string for quick test):

#include 
#include 

class MyClass
{
public:
      MyClass();
      ~MyClass();

      void someMethod();

      static std::map variable;
};

std::map MyClass::variable;

MyClass::~MyClass()
{
     // do some cleanup... using MyClass::variable, doesn't work
}

void MyClass::someMethod()
{
     variable["one"] = "value One"; // doesn't work...
}

int main(void)
{
        return 0;
}

Tags: BlackBerry Developers

Similar Questions

  • Call the function in LabView from a DLL, and then access the global variable of DLL

    I've created a DLL in LabWindows with a function and structure.  I want to call the function from LabView and then access the overall structure.  I am able to call the function in the DLL with a "call library function node" and has access to the return value, but I can't understand how to access the overall structure.  The structure is declared in the header DLL with __declspec (dllimport) struct parameters file.

    Is it possible to access this structure without using the library of network variables?

    My guess is that you need two bytes of padding after "in_out" and another to two bytes of padding after "anin."  The reason being that ints are 4 bytes, and most of them C compilers will align on 4-byte boundaries.  The struct will naturally start to such a limit (in fact, in Windows, it will probably start to an 8 byte boundary).  If you then count bytes in your structure, you are 70 byte after "in_out."  70 is not divisible by 4, so you need 2 bytes more to reach the next 4 byte boundary.  You can also you could reorganize your struct so that "anin" follows "in_out" and this is probably the best option if it won't cause you other problems.

    Unlike most C compilers, LabVIEW compressed structures as closely as possible, without filling.  I don't know enough about the history of LabVIEW and internal parts to explain the reasons and to do this performance penalty, but, as choice of LabVIEW "endianness", it is probably a remnant of the first versions of LabVIEW that were running on the Mac.

    If for some reason you want to force your C struct to match package LabVIEW, you can use the #pragma pack (x) directive, but I wouldn't recommend that here because you can control the C and LabVIEW.

    EDIT: in the cases where it was not clear, add padding to your cluster of LabVIEW, insert appropriate size or items at the place desired in the cluster.

  • Trouble accessing the Quiz Variables with HTML5

    Hello.

    I am trying to create a custom results page.

    I use the following code to return the total number of points scored,

    myScore = cp.variablesManager.getVariableValue ('cpQuizInfoPointsscored');

    This seems to return zero no matter how complete the quiz.

    How can I access the actual quantity of points marked on my personal page?

    Thank you

    Dongo

    You should be able to access the variable as you are, but as you have noticed, there are inconsistencies in the output of HTML5. Here's another way to get to the quiz variable:

    cp.model.data.quizzingData.quizInfoPointsScored;
    

    You will notice a lot of quiz data can be extracted from the cp.mode.data.quizzingData object.

    Best,

    Jim Leichliter

  • How to access the static class variable calendar / singleton?

    How can I access a timeline of a static class variable / singleton?

    You can pass any object to display list to your class when instantiating it.  all objects in the display list has a placement property that allows access to the stage and them you can use the correct path/name to your variable.

  • To access the added Variables of Classes dynamically

    I'm not sure what the terminology is here, but it's what I do.

    I added the officials in the field via a loop and add to the screen

         // loop through all of the elements and setup the forums
            for (int i = 0; i < size; i++)
            {
                c_ForumSelect frm = new c_ForumSelect();
                frm = (c_ForumSelect) v_forums.elementAt(i);
                hfm_forumselect new_forum = new hfm_forumselect(frm);
                mainManager.add(new_forum);
            }
    

    I wrote the code that allows to "highlight" the domain manager.

    Is there a way to 'read' the Manager added variables?

    For example, if I had a Variable called 'ID' within the hfm_forumselect... How I acceding that when sound highlighted on the main screen of the user interface...?

    Who is?

    You can add them to a datastructure, a vector, for example. When you add them. Or add the database instead. or you can use the container Manager, navigation using getFieldCount and getField (index).

  • To access the Global Variables in the functions/methods

    Which of the following statements is better in terms of performance and efficiency?

    public var a: int = 0;


    public void add (): void {}

    a += 5;

    }

    Addition();

    OR

    public var a: int = 0;

    public void Addition(b:int):int {}
    b += 5;
    Back to b;
    }

    a = (a) Addition;

    I saw a lot of guides discourages the use of global variables in the functions/methods, but I just don't understand why anyone would create a copy of the variable, modify this copy and to grant this value to another variable and throw.

    You must create an instance to pass to your function.  the parameter (for example, mov) does not create a separate instance and creates only a temporary pointer to the passed object.

    If an instance is prepared for gc, having spent this instance to any number of methods (as a parameter) delay / will not interfere with ca.

    and Yes.

    MOV ['x'] = mov.x,

    MOV ["rotation"] = MOV.rotation,

    MOV [anypropertystring] = MC.anyproperty

    Flash uses array notation to solve strings into objects:

    var var1:ClassType = new ClassType();

    This ['var1'] = this.var1

  • Static variables in the Page of the OFA

    Hello

    We have a requirement to show the popup message when changes are made in the page of the OFA. We use the static variable in the OPS page to store the initial values of some fields and whenever the popup needs to be shown, it compares the value of the static variable for the current value. If they are different then we are the message. It works perfectly fine when the page is accessed by the single user. But when several users access a single screen, it shows the message to a user even if the values are not changed by this user, but the other user has changed. My question is-

    1. do we need to use variables of session always for users multiple scenarios?
    2. How does the static variable in java? It is not unique to the session? If so, above the question shouldn't come.
    3. how to solve the problem above?

    Pointers on this would be a great help.

    Thank you
    Shree

    I did not understand the part same page can be accessed by different users. In any OA framework Page, the same page is accessible by several users. If you think abt the same data updated at the same time, then search functionality of Version number of the object in the context of OSTEOARTHRITIS.

    All instances of the VO are unique for each session. So no need to worry about this side here.

    Concerning
    Sumit

  • Not able to access the parent instance variable in outside of the methods in child

    Hello

    I don't get why I am not able to access the instance variable parent class apart from the example of the child class methods.
    class Parent
    {
         int a;
    }
    
    class Child extends Parent
    {
         a = 1; // Here i am getting a compilation error that Syntax error on token "a", VariableDeclaratorId expected after this token
         
         void someMethod()
         {
              a = 1;  // Here i am not getting any compilation error while accessing parent class variable
         }
    }
    Can someone let me know the exact reason for this, and what about the talks of error?

    Thank you
    Uday

    Published by: Udaya Shankara Gandhi on June 13, 2012 03:30

    You can only put assignments or expressions inside the methods, of the builders or the initializors class, or when you declare a variable.
    It has nothing to the child which stretches from Parent.

    class Parent {
        int a = 1;
    
        { a = 1; }
    
        public Parent() {
            a = 1;
        }
    
       public void method() {
           a = 1;
       }
    }
    
  • How to get the value of the global variable to test in the user interface of labview?

    Hello.

    Can someone please share examples and tell me how access the global variable to test using the interface labview user.

    I found some references and obtained from the method.

    I sent the link below

    https://decibel.NI.com/content/docs/doc-5501

  • How to bind static variables?

    In ActionScript, I tried binds a variable to one static variable to another class:

    var watcher: ChangeWatcher = BindingUtils.bindProperty (Thi, "dataProvider", StaticClass, "staticVariable");

    The changewatcher fires when loading, but it fires at all during execution.  And Yes, the static variable has the [Bindable] tag next to it.  I encountered this problem a few times before, and I decided to just go around it.  However, for the sake of clean and efficient code, any help on this would be greatly appreciated.

    See the comments at the bottom of this LiveDocs page:

    http://livedocs.Adobe.com/Flex/3/HTML/Help.HTML?content=databinding_2.html

    If this post answers your question or assistance, please mark it as such.

  • A problem with access to the public variable inside the function

    Hello

    I received this package and I get error 1120: 1120: access of undefined property aa

    Could you explain why I get this error?

    package somepackage {}

    import flash.display.DisplayObject;
    Import mx.containers.Canvas;

    SerializableAttribute public class SoundPictureSigns extends Canvas {}

    public var aa:int = 12;

    public void SoundPictureSigns (): void {}
    }


    public static void setUpSignSizes (): void {}

    trace ("AA =" + AA); ERROR here: 1120: access of undefined property aa
    {
    .......

    Can you help me?

    Concerning

    You cannot access an instance inside a static method variable. Either make the static or non-static method.

  • to access the variables defined in the Document class

    I can't evaluate the values established in my document class.

    My document class: ZoneViewer.as:

    SerializableAttribute public class ZoneViewer extends Sprite {}
    private var zone_area_alpha_low:Number is. 2;
    }

    This code exists on a frame in a movieclip in my main script:

    This.zone_shape.Alpha = zone_area_alpha_low;


    How to access the valeur.2 which is declared in my class: document ZoneViewer.as? "zone_area_alpha_low" does not work.

    Solution to the problem of access to a variable value (zone_area_alpha_low) from actionscript code framework in a movieclip.

    FYI... my project file structure:

    Project_Folder/MyApplication.fla
    Project_Folder/MyApplication.swf
    Project_Folder/classes/ZoneViewer.as
    --------------------
    Document class: classes. ZoneViewer

    {classes package

    import flash.display.MovieClip;

    SerializableAttribute public class ZoneViewer extends MovieClip {}

    public static var zone_area_alpha_low:Number =. 1;
    }
    }
    --------------------
    This code exists on the first frame of my movieclip in my .fla file.

    import classes. ZoneViewer;< i="" was="" missing="" this="" import="" statement="" within="" my="">
    This.zone_shape.Alpha = ZoneViewer.zone_area_alpha_low;< this="" finally="" is="" referenced="">

    Kudos to ntbdy for the light. Is there better ways to do this?

  • static reference with the global variable

    Hi, I used a static reference to a Subvi where I change a global variable before (3-4 years ago) and do not remember how I did it.

    It was something like these attachments, but now I'm using LabView 2013 instead of LV 8.6.

    The change in the overall operating system sees only not in the main vi (looks like the invoke node run vi does not work with globals).

    In addition the vi close with the invoke node close vi but not if I put the custom in the Subvi properties to automatically close.

    dkfire wrote:

    Why not call the sub vi as usual, just with the setting to display the front panel, when it is called?

    Use the connector pane to transfer the value of the sub vi Ok button when done.

    That's what I recommend.  If this is not possible for some reason, then you will need to use a flat Structure of the sequence to force the reading of the global variable after the Subvi is complete.

  • to access the data of the children with the static accessor of parent class

    I'm new to LVOOP. I'm trying to create accessors of data in the parent (static) class and use them in the child's class. I don't need them to be dynamic becase the accessors are identical for child and parent. Is it possible to access the data of a class without creating an accessor for each class?

    It is the dynamic method that I created that finally works. Once I found the VI "call Parent Method.vi' everything has worked.

    So now I created all my data as static accessors and my methods are dynamic (assuming that they do).

    Thanks for all the help.

  • How to access a global variable that is common between the different baskets project library

    My project consist of several libraries, after generation the library project packed for each library, I find it cannot share data in a global variable between different packaged project library file. For example: packed project library #1 contains VI variables global wirte 'position' and give it a value '400 '. Library #2 present another VI project try to read this global variable, but he gave reading of is NULL not "400". Why has this happened? Is it possible to solve, welcome any help, I wll appreciate for this!

    If you understand what is happening here...

    When you build a PPL, it takes in the .lvlib and also all the dependencies of the .lvlib.

    In your case, when you generate the Test Task.lvlib in a .lvlibp, she also pulls on a copy of the DataProcess.lvlib:GlobalsVariable.vi because it's addictive to read GlobalVar.vi.

    When your application runs, you end up with two copies of GlobalsVariable.vi in memory:

    DataProcess.lvlibp:GlobalsVariable.vi

    AND

    Test Task.lvlibp:: GlobalsVariable.vi (I don't know how PPLs namespace dependencies... If there is still the DataProcess.lvlibp)

    Because they are different screws (i.e. in a different namespace), they have their own memory and that's why you can't access the data.

    Your Test Task.lvlibp calls the version of GlobalsVariable.vi, he pulled the dependencies.

    To solve this problem - you must ensure that Task.lvlibp of Test calls the version of GlobalsVariable.vi of the DataProcess.lvlibp - you'll need to replace all instances with the version of the PPL. Of course, if you run DataProcess in the development environment, then it will always be bad namespaced, hence the suggestion to put your global variable VI in is own PPL that you then use in the process of data and Test tasks.

Maybe you are looking for