所以我最近尝试为我的一个 Raspberry Pi 项目尝试 GeoClue,但我一直坚持使用 gclue-simple()。运行 gclue_simple_new 似乎没问题,但是当我尝试使用 gclue_simple_new_finish() 获取指针时,程序给了我一个运行时错误:
(process:37607): GLib-GIO-CRITICAL **: 16:26:33.873: g_async_result_get_source_object: assertion 'G_IS_ASYNC_RESULT (res)' failed
(process:37607): GLib-GIO-CRITICAL **: 16:26:33.873: g_async_initable_init_finish: assertion 'G_IS_ASYNC_INITABLE (initable)' failed
(process:37607): GLib-GObject-CRITICAL **: 16:26:33.873: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
该程序的代码在这里:
#include <cstdlib>
#include <iostream>
#include <gclue-simple.h>
void geoclue_callback (GObject* srcObj, GAsyncResult* result, void* userData);
int main(){
std::cout << "Program started." << std::endl;
const char* DESKTOP_ID = "desktop1";
GClueAccuracyLevel accuracy = GCLUE_ACCURACY_LEVEL_CITY;
GCancellable* cancellablePtr = NULL;
GAsyncReadyCallback callback = geoclue_callback;
//gpointer is like void pointer.
gpointer usrDataPtr;
std::cout << "Variables declared." << std::endl;
gclue_simple_new(
DESKTOP_ID,
accuracy,
cancellablePtr,
callback,
usrDataPtr
);
std::cout << "geoclue service started." << std::endl;
GClueSimple* gclueServicePtr;
GAsyncResult* rstPtr;
GError** errsPtr;
//This part here causes runtime error.
gclueServicePtr = gclue_simple_new_finish(rstPtr, errsPtr);
}
void geoclue_callback (GObject* srcObj, GAsyncResult* result, void* userData) {
//Callback function for when Geoclue comes up with something
std::cout << "Results Ready." << std::endl;
}
我才刚刚接触 geoclue,而且我以前没有任何与 gtk 或 GNOME 项目相关的经验,所以我可能遗漏了一些明显的东西。
谢谢!