所以我写了下面的Qt插槽定义:
(标题)
public slots:
void test1();
(方法)
void myClass:test1()
{
//...
}
如果我在插槽定义中添加了一些代码,例如显示新窗口或新消息框的代码,则代码执行正常。但是,如果我坚持自己的功能,例如:
QString myClass::run_func(QString phase)
{
myOtherClass* moc = new myOtherClass();
moc->run(phase);
}
void myClass:test1()
{
run_func("hello world");
}
我的程序崩溃,并显示以下消息:
Sleep/Wake UUID: 03C9AE1C-32F3-4F2E-8396-80655C0AE1EA
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000010a08062020
VM Regions Near 0x10a08062020:
CG shared images 00000001c7eb2000-00000001c7eba000 [ 32K] r--/r-- SM=SHM
-->
STACK GUARD 00007fff5bc00000-00007fff5f400000 [ 56.0M] ---/rwx SM=NUL stack guard for thread 0
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 QtCore 0x0000000100d0c344 QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) + 52
1 QtWidgets 0x0000000100040f19 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 281
2 QtWidgets 0x00000001000427b2 QApplication::notify(QObject*, QEvent*) + 1442
3 QtCore 0x0000000100d0c0b2 QCoreApplication::notifyInternal(QObject*, QEvent*) + 114
4 QtWidgets 0x0000000100096344 QWidgetWindow::event(QEvent*) + 212
5 QtWidgets 0x0000000100040f2c QApplicationPrivate::notify_helper(QObject*, QEvent*) + 300
6 QtWidgets 0x0000000100043a1d QApplication::notify(QObject*, QEvent*) + 6157
7 QtCore 0x0000000100d0c0b2 QCoreApplication::notifyInternal(QObject*, QEvent*) + 114
8 QtGui 0x000000010068c9be QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) + 190
9 QtGui 0x000000010068b5c8 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) + 840
10 QtGui 0x000000010067b338 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 136
11 libqcocoa.dylib 0x000000010441a4c7 QCocoaEventDispatcherPrivate::processPostedEvents() + 295
12 libqcocoa.dylib 0x000000010441afd8 QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*) + 40
13 com.apple.CoreFoundation 0x00007fff89c72731 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 com.apple.CoreFoundation 0x00007fff89c63ea2 __CFRunLoopDoSources0 + 242
15 com.apple.CoreFoundation 0x00007fff89c6362f __CFRunLoopRun + 831
16 com.apple.CoreFoundation 0x00007fff89c630b5 CFRunLoopRunSpecific + 309
17 com.apple.HIToolbox 0x00007fff874eea0d RunCurrentEventLoopInMode + 226
18 com.apple.HIToolbox 0x00007fff874ee685 ReceiveNextEventCommon + 173
19 com.apple.HIToolbox 0x00007fff874ee5bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
20 com.apple.AppKit 0x00007fff8e83a3de _DPSNextEvent + 1434
21 com.apple.AppKit 0x00007fff8e839a2b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
22 com.apple.AppKit 0x00007fff8e82db2c -[NSApplication run] + 553
23 libqcocoa.dylib 0x0000000104419d44 QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 2404
24 QtCore 0x0000000100d0964d QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 397
25 QtCore 0x0000000100d0c652 QCoreApplication::exec() + 354
26 com.yourcompany.PwrCard 0x0000000100002f8b main + 91 (main.cpp:10)
27 com.yourcompany.PwrCard 0x0000000100002f24 start + 52
Thread 1:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 2:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x00007fff8c4ca662 kevent64 + 10
1 libdispatch.dylib 0x00007fff872d243d _dispatch_mgr_invoke + 239
2 libdispatch.dylib 0x00007fff872d2152 _dispatch_mgr_thread + 52
Thread 3:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 4:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 5:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 6:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 7:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 8:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 9:
0 libsystem_kernel.dylib 0x00007fff8c4c9e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff900a8f08 _pthread_wqthread + 330
2 libsystem_pthread.dylib 0x00007fff900abfb9 start_wqthread + 13
Thread 10:
0 libsystem_kernel.dylib 0x00007fff8c4c5a1a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff8c4c4d18 mach_msg + 64
2 com.apple.CoreFoundation 0x00007fff89c64155 __CFRunLoopServiceMachPort + 181
3 com.apple.CoreFoundation 0x00007fff89c63779 __CFRunLoopRun + 1161
4 com.apple.CoreFoundation 0x00007fff89c630b5 CFRunLoopRunSpecific + 309
5 com.apple.AppKit 0x00007fff8e9da16e _NSEventThread + 144
6 libsystem_pthread.dylib 0x00007fff900a7899 _pthread_body + 138
7 libsystem_pthread.dylib 0x00007fff900a772a _pthread_start + 137
8 libsystem_pthread.dylib 0x00007fff900abfc9 thread_start + 13
我的插槽与lineEdit的returnPressed()信号相关联。我无法弄清楚为什么这只会发生在用户定义的函数中。任何帮助将不胜感激。谢谢你们!
答案 0 :(得分:1)
解决了它.. run_func有一个字符串返回类型但实际上没有返回一个字符串。没有抓住这个,因为没有编译错误。