gpt4 book ai didi

c++ - Q共享库中的应用程序

转载 作者:行者123 更新时间:2023-12-03 16:40:04 26 4
gpt4 key购买 nike

我有一个最小的程序示例。它在编译为应用程序时可以运行,但作为共享库则无法运行。为什么是这样?

接口(interface).h

#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QThread>

#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif

EXTERNC void initialize();

#undef EXTERNC

class Q_DECL_EXPORT SharedLibrary :public QObject {
Q_OBJECT

public:
SharedLibrary();

private:
QCoreApplication * app;
};

接口(interface).cpp

#include "interface.h"
#define UNUSED(x) (void)(x)

SharedLibrary::SharedLibrary() {
int argc = 1;
char* argv[] = { (char*)"sharedlibrary.lib", NULL };

app = new QApplication(argc, argv);
QPushButton button("Hello World");
button.show();
app->exec();
}

void initialize() {
new SharedLibrary();
return;
}

int main (int argc, char** argv) {
UNUSED(argc);
UNUSED(argv);
new SharedLibrary();
return 0;
}

当我将应用程序编译为应用程序并运行 main 时,它工作得很好。当我将应用程序编译为库并运行 initialize 时,它崩溃了。有趣的是,同样的代码也可以在 Linux 上运行。下面是完整的堆栈跟踪:

arithmetic error FLOATING-POINT-INVALID-OPERATION signalled
[Condition of type FLOATING-POINT-INVALID-OPERATION]

Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1002E605A3}>)

Backtrace:
0: ("bogus stack frame")
1: ("foreign function: CUIDraw")
2: ("foreign function: _HIThemeCUIDrawWithOptions")
3: ("foreign function: _HIThemeCUIDrawWithRenderer")
4: ("foreign function: _HIThemeDrawAppleMenuTitle")
5: ("foreign function: _ZN13HIMenuBarView8DrawOnceE6CGRectS0_bbP9CGContext")
6: ("foreign function: _ZN13HIMenuBarView8DrawSelfEsPK9__HIShapeP9CGContext")
7: ("foreign function: _ZN6HIView12EventHandlerEP25OpaqueEventHandlerCallRefP14OpaqueEventRefPv")
8: ("foreign function: _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec")
9: ("foreign function: _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec")
10: ("foreign function: SendEventToEventTargetWithOptions")
11: ("foreign function: _ZN6HIView8SendDrawEsP13OpaqueGrafPtrPK9__HIShapeP9CGContext")
12: ("foreign function: _ZN6HIView23RecursiveDrawCompositedEPK9__HIShapeS2_jPS_P9CGContexthd")
13: ("foreign function: _ZN6HIView23RecursiveDrawCompositedEPK9__HIShapeS2_jPS_P9CGContexthd")
14: ("foreign function: _ZN6HIView14DrawCompositedEsP13OpaqueGrafPtrPK9__HIShapejPS_P9CGContext")
15: ("foreign function: _ZN6HIView6RenderEjP9CGContext")
16: ("foreign function: _ZN10WindowData20PrepareForVisibilityEv")
17: ("foreign function: _ShowHideWindows")
18: ("foreign function: ShowHide")
19: ("foreign function: _ZN9MBWindows18GetWindowOnDisplayEjh")
20: ("foreign function: _ZN15MenuBarInstance15ForEachWindowDoEhU13block_pointerFbP15OpaqueWindowPtrjE")
21: ("foreign function: _ZN15MenuBarInstance4HideE21MenuBarAnimationStylehhPhh")
22: ("foreign function: _ZN15MenuBarInstance21UpdateAggregateUIModeE21MenuBarAnimationStylehhh")
23: ("foreign function: _ZN15MenuBarInstance16ForEachMenuBarDoEU13block_pointerFvPS_E")
24: ("foreign function: _ZL25UpdateAllAggregateUIModes21MenuBarAnimationStyleh")
25: ("foreign function: SetSystemUIMode")
26: ("foreign function: -[NSApplication _setPresentationOptions:instance:flags:]")
27: ("foreign function: qt_plugin_instance")
28: ("foreign function: #x8B2BAB2")
29: ("foreign function: _ZN27QPlatformIntegrationFactory6createERK7QStringRK11QStringListRiPPcS2_")
30: ("foreign function: _ZN27QPlatformIntegrationFactory6createERK7QStringRK11QStringListRiPPcS2_")
31: ("foreign function: _ZN22QGuiApplicationPrivate25createPlatformIntegrationEv")
32: ("foreign function: _ZN22QGuiApplicationPrivate21createEventDispatcherEv")
33: ("foreign function: _ZN23QCoreApplicationPrivate4initEv")
34: ("foreign function: _ZN22QGuiApplicationPrivate4initEv")
35: ("foreign function: _ZN19QApplicationPrivate4initEv")
36: ("foreign function: _ZN13SharedLibraryC2Ev")
37: ("foreign function: initialize")
38: (CL-WEBENGINE::INITIALIZE)
39: (SB-INT:SIMPLE-EVAL-IN-LEXENV (CL-WEBENGINE::INITIALIZE) #<NULL-LEXENV>)
40: (EVAL (CL-WEBENGINE::INITIALIZE))
41: (SWANK::EVAL-REGION "(cl-webengine::initialize) ..)
42: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
43: (SWANK-REPL::TRACK-PACKAGE #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100318C0AB}>)
44: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
45: (SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME REPL evaluation request." #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100318C04B}>)
46: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
47: (SWANK/BACKEND:CALL-WITH-SYNTAX-HOOKS #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100318C02B}>)
48: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100318C02B}>)
49: (SWANK-REPL::REPL-EVAL "(cl-webengine::initialize) ..)
50: (SWANK-REPL:LISTENER-EVAL "(cl-webengine::initialize) ..)
51: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK-REPL:LISTENER-EVAL "(cl-webengine::initialize) ..)
52: (EVAL (SWANK-REPL:LISTENER-EVAL "(cl-webengine::initialize) ..)
53: (SWANK:EVAL-FOR-EMACS (SWANK-REPL:LISTENER-EVAL "(cl-webengine::initialize) ..)
54: (SWANK::PROCESS-REQUESTS NIL)
55: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
56: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
57: (SWANK/SBCL::CALL-WITH-BREAK-HOOK #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1002E680FB}>)
58: ((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "/Users/jmercouris/.emacs.d/elpa/slime-20200228.1656/swank/sbcl.lisp") #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-RE..
59: (SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1002E680FB}>)
60: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
61: (SWANK::CALL-WITH-BINDINGS ((*STANDARD-INPUT* . #<SWANK/GRAY::SLIME-INPUT-STREAM {1002E2F8E3}>)) #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1002E6811B}>)
62: ((FLET "FORM-FUN-5" :IN SWANK::HANDLE-REQUESTS))
63: (SWANK::HANDLE-REQUESTS #<SWANK::MULTITHREADED-CONNECTION {1002C0B143}> NIL)
64: (SWANK-REPL::REPL-LOOP #<SWANK::MULTITHREADED-CONNECTION {1002C0B143}>)
65: ((LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD))
66: (SWANK::CALL-WITH-BINDINGS NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD) {1002E680DB}>)
67: ((LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD))
68: ((FLET SB-UNIX::BODY :IN SB-THREAD::NEW-LISP-THREAD-TRAMPOLINE))
69: ((FLET "WITHOUT-INTERRUPTS-BODY-4" :IN SB-THREAD::NEW-LISP-THREAD-TRAMPOLINE))
70: ((FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::NEW-LISP-THREAD-TRAMPOLINE))
71: ((FLET "WITHOUT-INTERRUPTS-BODY-1" :IN SB-THREAD::CALL-WITH-MUTEX))
72: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::NEW-LISP-THREAD-TRAMPOLINE) {7A4DE7B}> #<SB-THREAD:MUTEX "thread result lock" owner: #<SB-THREAD:THREAD "repl-thr..
73: (SB-THREAD::NEW-LISP-THREAD-TRAMPOLINE #<SB-THREAD:THREAD "repl-thread" RUNNING {1002E605A3}> NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD) {1002E6054B}> NIL)
74: ("foreign function: call_into_lisp")
75: ("foreign function: new_thread_trampoline")

这是我的 .pro 文件的样子:

TEMPLATE = lib
TARGET = webengine
INCLUDEPATH += .
QT += core gui widgets webenginewidgets

# Input
HEADERS += interface.h
SOURCES += interface.cpp

最佳答案

我已经找到了答案,至少对于我的应用程序来说,显然我必须更改与我的共享库交互的代码的行为:

(sb-int:with-float-traps-masked (:invalid :inexact :overflow) (cl-webengine::run))

为了成功执行。

关于c++ - Q共享库中的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60637124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com