如何在 Bada 中传递控件作为参考?
总体而言,我想在 Bada 中创建一个基于框架的应用程序,它具有单个 UI 控件 - 标签。到目前为止一切顺利,但我希望它显示我选择的数字并每 X 秒重复减少一次。线程很好(我认为),但我无法将标签指针作为类变量传递。
//MyTask.h
//...
result Construct(Label* pLabel, int seconds);
//...
Label* pLabel;
//MyTask.cpp
//...
result
MyTask::Construct(Label* pLabel, int seconds) {
result r = E_SUCCESS;
r = Thread::Construct(THREAD_TYPE_EVENT_DRIVEN);
AppLog("I'm in da constructor");
this->pLabel = pLabel;
this->seconds = seconds;
return r;
}
//...
bool
Threading::OnAppInitializing(AppRegistry& appRegistry)
{
// ...
Label* pLabel = new Label();
pLabel = static_cast<Label*>(pForm->GetControl(L"IDC_LABEL1"));
MyTask* task = new MyTask();
task->Construct(&pLabel); // HERE IS THE ERROR no matching for Label**
task->Start();
// ...
}
问题是我已经尝试了 *、& 的所有可能组合,以及组合学中已知的普通 pLabel...
我得到这个并不是非常重要(它只是用于训练),但我很想了解如何来解决问题。
In the big picture I want to create a frame based application in Bada that has a single UI control - a label. So far so good, but I want it to display a number of my choosing and decrement it repeatedly every X seconds. The threading is fine (I think), but I can't pass the label pointer as a class variable.
//MyTask.h
//...
result Construct(Label* pLabel, int seconds);
//...
Label* pLabel;
//MyTask.cpp
//...
result
MyTask::Construct(Label* pLabel, int seconds) {
result r = E_SUCCESS;
r = Thread::Construct(THREAD_TYPE_EVENT_DRIVEN);
AppLog("I'm in da constructor");
this->pLabel = pLabel;
this->seconds = seconds;
return r;
}
//...
bool
Threading::OnAppInitializing(AppRegistry& appRegistry)
{
// ...
Label* pLabel = new Label();
pLabel = static_cast<Label*>(pForm->GetControl(L"IDC_LABEL1"));
MyTask* task = new MyTask();
task->Construct(&pLabel); // HERE IS THE ERROR no matching for Label**
task->Start();
// ...
}
The problem is that I have tried every possible combination of *, &, and just plain pLabel, known in Combinatorics...
It is not extremely important that I get this (it is just for training) but I am dying to understand how to solve the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过吗:
我想指出您缺少 MyTask::Construct 的第二个参数。
Have you tried:
And by that I want to point out that you are missing the second parameter for MyTask::Construct.
不,我没有。我不知道第二个参数。但这个问题已经解决了。如果我声明一个变量
Object* __pVar
,那么构造函数应该是Init(Object* pVar)
,如果我想初始化一个实例变量,我应该写No, I haven't. I don't know of a second parameter. But this problem is solved. If I declare a variable
Object* __pVar
, then the constructor should beInit(Object* pVar)
, and if I want to initialize an instance variable I should write