在哪里声明应用程序中使用的变量(wxWidgets)?

时间:2019-04-17 14:38:27

标签: c++ user-interface wxwidgets

我创建了@override void initState() { HelperDatabase1().displayWorkTypes().then((result) { setState(() { workTypes = result; }); }); } child: DropdownButton<DataWorkTypes>( isExpanded: true, value: _workTypes, items: workTypes.map((DataWorkTypes value) { return DropdownMenuItem<DataWorkTypes>( value: value, child: Text( value.d, // same label as before overflow: TextOverflow.ellipsis, ), ); }).toList(), onChanged: (value) => setState(() { int index = value.i; // here is your index _workTypes = value; }), style: Theme.of(context).textTheme.title, ), 类,该类继承自MyApp,并向其中添加了一些组件变量:

wxApp

然后我在class MyApp : public wxApp { GameBoard* gb; Player* player; bool lightTheme; std::vector<wxBitmapToggleButton *> cardImages; public: MyApp(); virtual bool OnInit(); void displayImages(wxFrame *, wxGridSizer *); void OnCardSelect(wxCommandEvent&); }; 中设置它们的值:

MyApp::OnInit

并且当我在void MyApp::OnInit() { //... player = new Player(1); //... } 函数中使用Player类方法时,一切正常,但是当我在事件函数中使用它时,我得到的结果很奇怪(例如 empty的大小MyApp::OnInit类中声明的std::vector<int>返回18446744073709551540)。事件功能:

Player

调用void MyApp::OnCardSelect(wxCommandEvent& event) { std::cout << (player->getChosen()).size() << std::endl; // above line only for debugging, getChosen() returns const std::vector<int>&, which should be empty, but it print strange result wxBitmapToggleButton *selectedCard = dynamic_cast<wxBitmapToggleButton *>(event.GetEventObject()); player -> toggleChosen(int(selectedCard -> GetId())); } (使用MyApp之后,OnInit的组件变量会发生什么,我该在哪里声明和更改这些变量的值?

0 个答案:

没有答案