首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从外部访问类对象

从外部访问类对象
EN

Stack Overflow用户
提问于 2021-03-11 20:18:22
回答 1查看 278关注 0票数 0

我在TouchGFX设计器上创建了一个基本项目,并使用touchgfx库在我自己的cpp文件中编写了一个函数。我希望当单击按钮时,函数从我自己的cpp文件调用ScreenView.cpp或ScreenViewBase.cpp,并更改框的颜色。

这是我的cpp文件。

代码语言:javascript
复制
#include <touchgfx/Color.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <gui/screen1_screen/Screen1View.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <touchgfx/widgets/Box.hpp>

ChangeColor::ChangeColor()
{
    Screen1View::box1;
    box1.setColor(touchgfx::Color::getColorFrom24BitRGB(51, 168, 35));
    box1.invalidate();
}

这是我想要调用函数的Screen1View.cpp。

代码语言:javascript
复制
#include<gui/ChangeColor.hpp>
#include <touchgfx/Color.hpp>

Screen1View::Screen1View():
    buttonCallback(this, &Screen1View::buttonCallbackHandler)
{

}

void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
    button1.setAction(buttonCallback);

}

void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}
void Screen1View::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
    if (&src == &button1)
    {
        //Interaction1
        //When button1 clicked execute C++ code
        //Execute C++ code
        //ChangeColor();
        ChangeColor();
    
    }
}

这是声明该框的Screen1BaseView.hpp

代码语言:javascript
复制
#define SCREEN1VIEWBASE_HPP

#include <gui/common/FrontendApplication.hpp>
#include <mvp/View.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/widgets/Button.hpp>

class Screen1ViewBase : public touchgfx::View<Screen1Presenter>
{
public:
    Screen1ViewBase();
    virtual ~Screen1ViewBase() {}
    virtual void setupScreen();

protected:
    FrontendApplication& application() {
        return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
    }

    /*
     * Member Declarations
     */
    touchgfx::Box __background;
    touchgfx::Box box1;
    touchgfx::Button button1;

private:

};

我不能打开盒子。有什么办法可以做到吗?

EN

回答 1

Stack Overflow用户

发布于 2021-03-11 21:00:10

TouchGFX采用MPV架构,即模型-演示者-视图。重点是模型和视图不能相互访问。

在您的例子中,您的cpp文件扮演模型的角色,因此它不允许访问View中的元素。这就是你不能访问的原因。您需要一个演示者来处理连接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66582427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档