GLib-GObject-CRITICAL ...断言'quark>0'失败 [英] GLib-GObject-CRITICAL ... assertion 'quark > 0' failed

查看:98
本文介绍了GLib-GObject-CRITICAL ...断言'quark>0'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触Gtk编程.我正在使用Gtkmm库为我的应用程序编写一个简单的GUI.

I'm fairly new to Gtk programming. I'm using the Gtkmm library to write a simple GUI for my application.

GUI是较大应用程序的一部分,该应用程序实际上可以编译为两个单独的可执行文件,但是我不认为这是有意义的,因为此问题仅涉及两个可执行文件之一.

The GUI is part of a larger application, which actually compiles to two separate executables, however I don't believe this is relevant since this question only concerns one of the two executables.

无论如何,我在client.cpp中有以下代码:

Anyway, I have the following code in client.cpp:

#include "client.hpp"

int main() {
    auto builder = Gtk::Builder::create();
}

在client.hpp中,我仅包含iostream,glibmm.h和各种gtkmm小部件标题以及gtkmm/builder.h.

And in client.hpp I'm simply including iostream, glibmm.h, and various gtkmm widget headers, as well as gtkmm/builder.h.

我的makefile很乱,但是在这里:

My makefile is a mess, but here it is:

CXXFLAGS= -std=c++14 -g
LDFLAGS=-lgmp -pthread $(shell pkg-config -libs gtkmm-3.0)
SERVER_EXE=server
CLIENT_EXE=client
CXX=g++
DIST_DIR=.
BUILD_DIR=./build

SERVER_CXXFLAGS=
CLIENT_CXXFLAGS=$(shell pkg-config --cflags gtkmm-3.0)

INCLUDE_DIRS=./include
INCLUDE_PARAMS=$(foreach d, $(INCLUDE_DIRS), -I$d)

SERVER_OBJECTS=rsa.o server_entry.o server.o
SERVER_OBJECT_PATHS=$(foreach o, $(SERVER_OBJECTS), $(BUILD_DIR)/$o)

CLIENT_OBJECTS=resources.o client.o
CLIENT_OBJECT_PATHS=$(foreach o, $(CLIENT_OBJECTS), $(BUILD_DIR)/$o)

all: $(SERVER_OBJECT_PATHS) $(CLIENT_OBJECT_PATHS)
    mkdir -p $(DIST_DIR)
    $(CXX) $(CLIENT_OBJECT_PATHS) -o $(DIST_DIR)/$(CLIENT_EXE) $(LDFLAGS)
    $(CXX) $(SERVER_OBJECT_PATHS) -o $(DIST_DIR)/$(SERVER_EXE) $(LDFLAGS)

clean:
    rm -rf $(BUILD_DIR)
    rm $(DIST_DIR)/$(CLIENT_EXE) $(DIST_DIR)/$(SERVER_EXE)

$(BUILD_DIR)/%.o: %.cpp
    mkdir -p $(BUILD_DIR)
    $(CXX) -c $< $(INCLUDE_PARAMS) -o $@ $(CXXFLAGS) $(SERVER_CXXFLAGS) $(CLIENT_CXXFLAGS)

resources.cpp:
    glib-compile-resources --target=resources.cpp --generate-source windows.gresource.xml

我意识到这是很多事情要做的,因为它实际上是在构建两个可执行文件,但是对于这个问题,您可以放心地只考虑与 client 程序有关的事情.

I realise that's a lot to take in, since it's actually building two executables, but for this question you can safely only regard things which are related to the client program.

右下方的规则用于将我制作的林间空地文件转换为可链接到我的client.cpp文件的c ++文件.

The rule right at the bottom is used to turn the glade file I made into a c++ file which can be linked to my client.cpp file.

无论如何,当我运行程序时,会得到以下输出:

Anyway, when I run my program I get the following output:

(process:16593): GLib-GObject-CRITICAL **: 23:15:27.886: g_object_set_qdata_full: assertion 'quark > 0' failed

对于此错误消息的含义,我完全不知所措.由于我对这个库不是很有经验,所以我不确定该如何做.我还尝试在代码后添加一行以从资源加载构建器窗口小部件,但这会导致更严重的错误并被隔离.我希望如果我能解决这个第一个错误,其他所有内容都可以解决.有什么想法吗?谢谢!

I'm at a complete loss as to what this error message could mean. Since I'm not very experienced with this library, I'm not sure quite what to make of it. I also tried adding a line after my code to load the builder widgets from a resource, but that created even more critical errors and segfaulted. I'm hoping if I can fix this first error, everything else will fall into place. Any thoughts? Thanks!

更新1 :当我将client.cpp的源更改为提供的源代码

UPDATE 1: When I change the source of client.cpp to the source code supplied here, it works perfectly! So that's odd..

推荐答案

我很确定在调用任何Glib/Gtk函数之前,必须使用 Glib :: init()初始化GLibMM. Gtk :: Application :: create()将为您完成此操作,这就是该示例正常运行的原因.

I'm pretty sure GLibMM must be initialized with Glib::init() before you call any Glib/Gtk functions. Gtk::Application::create() will do that for you, that's why the example just works.

这篇关于GLib-GObject-CRITICAL ...断言'quark&gt;0'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆