Qt QPlainTextEdit is crashing
Qt QPlainTextEdit is crashing
我正在使用一个记录器窗口,这是一个从QPlainTextEdit
继承的简单小部件。
现在我需要同时打印几条消息(我用互斥锁使这个线程安全),但它还是崩溃了。这是来自 gdb 的消息
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff56c5cb9 in QTextLine::draw(QPainter*, QPointF const&, QTextLayout::FormatRange const*) const ()
from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
我正在使用Qt 5.4,但尝试了Qt 5.7,崩溃仍然存在。有人有提示吗?我应该从其他小部件继承吗?
正如人们在上面评论的那样,问题可能在于你做事的方式。因此,以下是如何处理您的情况的推荐方法:使用 QThread,不要使用互斥锁。
Qt使用信号/插槽进行线程安全通信。有关如何快速入门的示例:
class A : public QObject
{
Q_OBJECT
// ...
public slots:
void run();
}
任何你想从另一个新线程中运行的类都需要一个"run"槽,你可以随心所欲地称呼它,但它是你在下面的实现中启动它后在新线程中调用的第一个函数:
// Create and start the thread
QThread *t = new QThread;
t->start();
// Create an object of your class and move it to the thread
A* a = new A();
a->moveToThread(t);
// Now actually run it in the thread through the signal slot system
QMetaObject::invokeMethod(a, "run", Qt::QueuedConnection);
我希望这能说清楚,如果你有任何问题,请告诉我。
相关文章:
- Why is UINT32_MAX + 1 = 0?
- C++错误:"error: int aaa::bbb is protected within this context"
- 创建具有 new in 函数和"this is nullptr"异常的对象
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- Is !NaN not a NaN?
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- Where is std::hardware_destructive_interference_size?
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- What is unordered_set in C++
- 你如何理解"std: :forward is just syntactic sugar"?这是真的吗?
- C++ "error: use of overloaded operator '*' is ambiguous"似乎只有一场比赛
- C++ is calculating wrong
- Is it good to use SDL_PIXELFORMAT_UNKNOWN?
- reference_wrapper导致"incomplete type is not allowed"
- 为什么即使在定义之后仍存在"Identifier is undefined error "?
- 结构中的错误"Incomplete type is not allowed"
- Crash in boost::archive::text_iarchive in_archive {is} boost
- Qt QPlainTextEdit is crashing