„winrt::Simply_Sense::implementation::SensorPage“: abstrakte Klasse kann nicht instanziiert werden

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: „winrt::Simply_Sense::implementation::SensorPage“: abstrakte Klasse kann nicht instanziiert werden

by Guest » 14 Jan 2025, 13:10

Ich versuche, eine API-Antwort an eine andere Funktion zu senden. Ich möchte ein Objekt der Klasse erstellen, damit ich die benötigte Funktion aufrufen kann, aber es heißt, dass es sich um eine abstrakte Klasse handelt. Ich mache das alles in Visual Studio mit Winui3. Der Fehler ist:

Code: Select all

'winrt::Simply_Sense::implementation::SensorPage': cannot instantiate abstract class.
Die API-Antwort wird in der Variablen sensorMapData gespeichert. Die Antwort ist HTML. Ich muss das an die Funktion „loadhtmlfile“ auf einer anderen Seite senden, wo es in eine Webansicht geladen werden kann.

Code: Select all

//this object gives me the error
winrt::Simply_Sense::implementation::SensorPage sensorPage;

//this is the header file with the class
namespace winrt::Simply_Sense::implementation
{
struct SensorPage : SensorPageT
{
public:
SensorPage();
int32_t MyProperty();
void MyProperty(int32_t value);
void initialize();
void LoadHtmlFile(const std::string& sensordata);
void OnPageLoaded(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&);
void Back_Button_View(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);

private:
Token_model tokenModel;
int32_t m_myProperty;
};
}

namespace winrt::Simply_Sense::factory_implementation
{
struct SensorPage : SensorPageT
{
};
}

//This is the code for getting the api response
std::string Token_model::getSensorMap(const std::string& refreshToken)
{
std::string sensorMapData;
try
{
std::string device_id = "8de6f55e-dbe6-4a5b-ba7e-93e12c114972";
OutputDebugStringA(("Device id = " + device_id + "\n").c_str());

sensorMapData = performGetWebView("https://beta.simplysense.nl/api/device-groups/view/" + device_id, refreshToken);
OutputDebugStringA(("Sensordata: " + sensorMapData + "\n").c_str());

winrt::Simply_Sense::implementation::SensorPage sensorPage;

writeHtmlToFile(sensorMapData, "C:/xampp/htdocs/sensorpage.html");
}
catch (const std::exception& e)
{
OutputDebugStringA(e.what());
throw;
}

if (!sensorMapData.empty())
{
return sensorMapData;
}
else
{
throw std::runtime_error("Het is niet gelukt om de response te decoderen! sensormap\n");
}
}

//function for loading the api response in webview
void SensorPage::LoadHtmlFile(const std::string& sensordata)
{
try {
std::string htmlContent = "Hello world!!!";
std::string dataUri = "data:text/html;charset=utf-8, " + htmlContent;

if (MyWebView())
{
MyWebView().Source(winrt::Windows::Foundation::Uri(winrt::to_hstring(dataUri)));
}
else
{
throw std::runtime_error("MyWebView is not initialized.");
}
}
catch (const std::exception& e)
{
OutputDebugStringA(e.what());
}
}
Ich habe versucht, die Funktion „loadhtmlfile“ in eine andere Klasse einzufügen, aber das hat nicht funktioniert.

Top