Repository navigation
|
Hi. I just started playing with libqt6zig today. Not an expert in zig or qt (or c++ for that matter), and I'm unsure if this is a legit bug or a self-inflicted foot/gun scenario. Apologies if this is the wrong place to post this. I am unable to call a SummaryWherever a pointer must convert to a second base class, the generated code uses
The defect appears in two forms:
Both are the same root cause, and the README currently describes the second one as an unrelated limitation with a workaround that only appears to work. ReproducingThe receiver form, on any widget: const w = qopenglwidget.QOpenGLWidget.new(...);
const dpr = w.devicePixelRatioF(); // segfault: jump to address 0Observed on Debian 13 arm64, Qt 6.8.2, Zig 0.16.0, Mesa llvmpipe. A single-inheritance call on the same object is fine, which isolates the cause. CauseThe generated wrapper reinterprets the pointer: pub fn devicePixelRatioF(self: QOpenGLWidget) f64 {
return qtc.QPaintDevice_DevicePixelRatioF(@ptrCast(self.ptr));
}
The C entry point is declared on the base type, so nothing downstream can recover the offset: double QPaintDevice_DevicePixelRatioF(const QPaintDevice* self);
The generator already has the information needed to detect the case. Blast radiusThe pattern
The README's two workarounds do not hold"Use QStylePainter instead of QPainter"The limitations section reads:
The generated constructors suggest the attribution is wrong. pub fn new2(param1: anytype) QPainter {
return .{ .ptr = qtc.QPainter_new2(@ptrCast(param1.ptr)) };
}
"Upcast manually with
|
Replies: 3 comments
|
Hi! Thanks for the interest!
While there is no official policy for this project, please follow these guidelines as a form of general etiquette. This is a lot of jargon to sift through for what appears to be a legitimate bug. I'm going to summarize this as a bug with classes that have multiple inheritance and the requirement to use helper methods that are currently not defined in the library. I was under the impression that pointer casts would apply for upcasting to parent classes and that appears to be a false assumption in many scenarios. I've historically tested this with many dual inherited classes but not directly dual-inherited in all cases such as QFile. Ultimately, you have my gratitude since I believe that this solves a few bugs I've been trying to resolve and assuming I can have this generated smoothly, it will probably call for properly documenting somehow. This deserves an issue but I need to pare it down quite a bit before doing so. |
|
I have an implementation working for this, not quite as suggested and there are some inaccuracies in the analysis that still leave us with some limitations. Ultimately, I believe that things are much improved as all of the crashes I've been troubleshooting are resolved. I hope to get the fix pushed out soon, ideally reviewed with some fresh eyes. Thanks again for this report. I would still encourage using your first brain for development and getting comfortable with the library. Once you have the mental model, it really is empowering! |
|
Hi again! These changes are now merged and available. You should be able to pull them down with a new fetch. There are a few notes I thought were important to share. I believe the upcasting information in the documentation is valid and while these could be replaced/augmented by The most critical corrections from the initial report is that this implementation does not resolve parameter-based secondary table references like the Everything net, having this properly resolved and being able to remove the hack of a workaround bring great peace of mind. The change is a little bit noisy but it should still be decipherable. Thanks again! Happy hacking! EDIT: After another update, the upcasting at call sites is now optional. The comptime implementation ended up not being that expensive and the result is that bare parameters will also succeed. The README has also been simplified to the mandatory use cases. |
Hi again!
These changes are now merged and available. You should be able to pull them down with a new fetch.
There are a few notes I thought were important to share. I believe the upcasting information in the documentation is valid and while these could be replaced/augmented by
as<T>helper methods, I think that adding more upcasting helper methods than are required might introduce more cognitive load than it is currently worth. There is now a table for which parent types have upcast (and potentially downcast, more on that further) methods and what types they need to be invoked for. As implemented, the current base class implementations for inherited objects call the helper method directl…