Issue 501 (#505)

* Fixed #501 (more Qt ownership management) - this commit contains some more changes because I had to regenerate the Qt binding sources.

* Fixed #501 (Qt object ownership transfer) - repairs, added tests

* Updated Jenkinsfile to not publish a PR build

* Update Jenkinsfile - exclude PR's from build
This commit is contained in:
Matthias Köfferlein 2020-02-21 18:25:22 +01:00 committed by GitHub
parent 161068c70a
commit 69e7704430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 252 additions and 23 deletions

6
Jenkinsfile vendored
View File

@ -31,8 +31,10 @@ node("master") {
parallel(
"Publish": {
// from shared library
publish(BRANCH_NAME, target, target_dir)
// from shared library - only publish for normal branch, not for PR
if (! BRANCH_NAME.startsWith('PR')) {
publish(BRANCH_NAME, target, target_dir)
}
},
"Unit testing": {

View File

@ -170,7 +170,7 @@ if [ $update != 0 ]; then
if [ $reuse == 0 ]; then
for d in Qt*; do
for d in $qt_mods; do
echo "--------------------------------------------------------"
echo "Parsing $d ..."
@ -181,7 +181,7 @@ if [ $update != 0 ]; then
echo "Running gcc preprocessor .."
# By using -D_GCC_LIMITS_H_ we make the gcc not include constants such as ULONG_MAX which will
# remain as such. This way the generated code is more generic.
gcc -I$qt -fPIC -D_GCC_LIMITS_H_ -E -o allofqt.x allofqt.cpp
gcc -std=gnu++98 -I$qt -fPIC -D_GCC_LIMITS_H_ -E -o allofqt.x allofqt.cpp
echo "Stripping hash lines .."
egrep -v '^#' <allofqt.x >allofqt.e
@ -225,7 +225,7 @@ else
cd $work_dir
fi
for d in Qt*; do
for d in $qt_mods; do
echo "--------------------------------------------------------"
echo "Processing $d ..."

View File

@ -482,6 +482,10 @@ drop_method "QClipboardEvent", /QClipboardEvent::data/
drop_method "QClipboardEvent", /QClipboardEvent::QClipboardEvent\(QEventPrivate/
drop_method "QCursor", /QCursor::QCursor\s*\(\s*Qt::HANDLE/ # not available on WIN
drop_method "QApplication", /QApplication::compressEvent/ # QPostEventList is missing
drop_method "QApplication", /QApplication::commitDataRequest/ # Signal with a out argument (QSessionManager &)
drop_method "QApplication", /QApplication::saveStateRequest/ # Signal with a out argument (QSessionManager &)
drop_method "QApplication", /QApplication::saveState\s*\(/ # QSessionManager is not always available
drop_method "QApplication", /QApplication::commitData\s*\(/ # QSessionManager is not always available
drop_method "QWidget", /QWidget::painters/ # whatever that is, it's not a method ..
drop_method "QWidget", /QWidget::handle/ # not available on WIN
drop_method "QPixmap", /QPixmap::handle/ # not available on WIN
@ -597,6 +601,7 @@ rename "QIcon", /QIcon::pixmap\(int\s+extent/, "pixmap_ext"
rename "QKeySequence", /QKeySequence::QKeySequence\(QKeySequence::StandardKey/, "new_std"
keep_arg "QBoxLayout", /::addLayout/, 0 # will take ownership of layout
keep_arg "QGridLayout", /::addLayout/, 0 # will take ownership of layout
keep_arg "QWidget", /::setLayout\s*\(/, 0 # will take ownership of layout
keep_arg "QLayout", /::addChildLayout/, 0 # will take ownership of layout
keep_arg "QLayout", /::addItem/, 0 # will take ownership of item
keep_arg "QTreeWidgetItem", /::addChild\(/, 0 # will take ownership of the child
@ -618,6 +623,8 @@ keep_arg "QGraphicsScene", /::addItem\(/, 0 # will take ownership of the item
owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidgetItem\s+\*/, 0 # will construct a new object owned by arg #0
owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidget\s+\*/, 0 # will construct a new object owned by arg #0
owner_arg "QListWidgetItem", /::QListWidgetItem\(QListWidget\s+\*/, 0 # will construct a new object owned by arg #0
owner_arg "QObject", /::setParent\(QObject\s+\*/, 0 # will make self owned by arg #0
owner_arg "QWidget", /::setParent\(QWidget\s+\*/, 0 # will make self owned by arg #0
# this would make sense, but the pointer is const: so how can setItemPrototype take
# over ownership of it?
# keep_arg "QTableWidget", /::setItemPrototype\(/, 0 # will take ownership of the child

View File

@ -713,6 +713,7 @@ rename "QIcon", /QIcon::pixmap\(int\s+extent/, "pixmap_ext"
rename "QKeySequence", /QKeySequence::QKeySequence\(QKeySequence::StandardKey/, "new_std"
keep_arg "QBoxLayout", /::addLayout/, 0 # will take ownership of layout
keep_arg "QGridLayout", /::addLayout/, 0 # will take ownership of layout
keep_arg "QWidget", /::setLayout\s*\(/, 0 # will take ownership of layout
keep_arg "QLayout", /::addChildLayout/, 0 # will take ownership of layout
keep_arg "QLayout", /::addItem/, 0 # will take ownership of item
keep_arg "QTreeWidgetItem", /::addChild\(/, 0 # will take ownership of the child
@ -734,6 +735,8 @@ keep_arg "QGraphicsScene", /::addItem\(/, 0 # will take ownership of the item
owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidgetItem\s+\*/, 0 # will construct a new object owned by arg #0
owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidget\s+\*/, 0 # will construct a new object owned by arg #0
owner_arg "QListWidgetItem", /::QListWidgetItem\(QListWidget\s+\*/, 0 # will construct a new object owned by arg #0
owner_arg "QObject", /::setParent\(QObject\s+\*/, 0 # will make self owned by arg #0
owner_arg "QWidget", /::setParent\(QWidget\s+\*/, 0 # will make self owned by arg #0
# this would make sense, but the pointer is const: so how can setItemPrototype take
# over ownership of it?
# keep_arg "QTableWidget", /::setItemPrototype\(/, 0 # will take ownership of the child

View File

@ -50,7 +50,7 @@ grammar CPP
end
rule a
s ( "__attribute__" s attribute_value s / "__asm" s attribute_value s / "__extension__" s )*
s ( "__attribute__" s attribute_value s / "__asm" s attribute_value s / "__extension__" s / "decltype" s attribute_value s )*
end
rule unary_op
@ -110,11 +110,11 @@ grammar CPP
end
rule bool_type
"bool" <PBoolType>
"bool" ![a-zA-Z0-9_] <PBoolType>
end
rule void_type
"void" <PVoidType>
"void" ![a-zA-Z0-9_] <PVoidType>
end
rule float_type
@ -134,12 +134,20 @@ grammar CPP
end
rule virtual_spec
"virtual" <PVirtual>
"virtual" ![a-zA-Z0-9_] <PVirtual>
end
rule explicit_key
"explicit" ![a-zA-Z0-9_]
end
rule mutable_key
"mutable" ![a-zA-Z0-9_]
end
rule member_declaration_wo_semicolon
template:( d:template_decl s )?
attr:( ( "explicit" / "mutable" / storage_class / inline_spec / virtual_spec ) s )*
attr:( ( explicit_key / mutable_key / storage_class / inline_spec / virtual_spec / constexpr_key ) s )*
t:type
# type declaration ends with a } .. does not need a semicolon
# (i.e. nested struct or enum)
@ -155,7 +163,7 @@ grammar CPP
rule member_declaration_w_semicolon
template:( d:template_decl s )?
attr:( ( "explicit" / "mutable" / storage_class / inline_spec / virtual_spec ) s )*
attr:( ( explicit_key / mutable_key / storage_class / inline_spec / virtual_spec / constexpr_key ) s )*
t:type
# opposite case (member_see declaration_wo_semicolon)
# (i.e. nested struct or enum)
@ -214,11 +222,11 @@ grammar CPP
end
rule concrete_type
( class_or_struct_type / enum_type / float_type / char_type / int_type / bool_type / void_type / typeof / class_id )?
( constexpr_key / class_or_struct_type / enum_type / float_type / char_type / int_type / bool_type / void_type / typeof / class_id )?
end
rule cv
( "const" ![a-zA-Z0-9_] / "__const" ![a-zA-Z0-9_] / "volatile" ![a-zA-Z0-9_] / "__volatile" ![a-zA-Z0-9_] ) <PCV>
( constexpr_key / "const" ![a-zA-Z0-9_] / "__const" ![a-zA-Z0-9_] / "volatile" ![a-zA-Z0-9_] / "__volatile" ![a-zA-Z0-9_] ) <PCV>
end
rule pointer
@ -247,8 +255,12 @@ grammar CPP
ellipsis
end
rule noexcept_spec
"noexcept" ( s "=" s block / s "(" s block ")" )?
end
rule func_spec
"(" s fa:( a:func_args )? s ")" cvspec:( s cv:cv )? ( s "throw" s "(" s ( type_wo_comma s )? ")" )* a <PFuncSpec>
"(" s fa:( a:func_args )? s ")" cvspec:( s cv:cv )? ( s "throw" s "(" s ( type_wo_comma s )? ")" / s noexcept_spec )* ( s override_key )? a <PFuncSpec>
end
rule member_pointer
@ -308,6 +320,14 @@ grammar CPP
( "static" ![a-zA-Z0-9_] / "extern" ![a-zA-Z0-9_] ( s '"C"' / s '"C++"' / s '"Pascal"' )? ) <PStorageClass>
end
rule override_key
"override" ![a-zA-Z0-9_]
end
rule constexpr_key
"constexpr" ![a-zA-Z0-9_]
end
rule inline_spec
"inline" ![a-zA-Z0-9_] <PInline>
end
@ -346,6 +366,10 @@ grammar CPP
"using" ![a-zA-Z0-9_] ( s "namespace" )? ![a-zA-Z0-9_] s id:qualified_id a ";" <PUsing>
end
rule static_assert
"static_assert" s "(" s block s ")"
end
rule typedef
a "typedef" ![a-zA-Z0-9_] s t:type a ";" <PTypedef>
end
@ -362,8 +386,9 @@ grammar CPP
rule declaration_w_semicolon
template:( d:template_decl s )?
template_member:( d_member:template_decl s )?
attr:( ( storage_class / inline_spec ) s )*
attr:( ( storage_class / inline_spec / constexpr_key ) s )*
a
( constexpr_key s )?
t:type
# type declaration ends with a } .. does not need a semicolon
# (i.e. nested struct or enum)
@ -378,8 +403,9 @@ grammar CPP
rule declaration_wo_semicolon
template:( d:template_decl s )?
attr:( ( storage_class / inline_spec ) s )*
attr:( ( storage_class / inline_spec / constexpr_key ) s )*
a
( constexpr_key s )?
t:type
# opposite case (see declaration_wo_semicolon)
# (i.e. nested struct or enum)
@ -398,7 +424,7 @@ grammar CPP
rule namespace
"namespace" ![a-zA-Z0-9_] s n:id
a "{" decls:( a ( ";" / using / typedef / namespace / declaration ) )* s "}" <PNamespace>
a "{" decls:( a ( ";" / static_assert / using / typedef / namespace / declaration ) )* s "}" <PNamespace>
end
rule extern_decl
@ -407,7 +433,7 @@ grammar CPP
end
rule module
( a ( ";" / using / typedef / namespace / extern_decl / declaration ) )* s <PModule>
( a ( ";" / static_assert / using / typedef / namespace / extern_decl / declaration ) )* s <PModule>
end
end

View File

@ -1669,6 +1669,18 @@ END
end
def produce_keep_self(ofile, alist, obj, owner_args = [])
owner_args.each do |a|
ofile.puts(" if (#{alist[a]}) {");
ofile.puts(" qt_gsi::qt_keep (#{obj});")
ofile.puts(" } else {");
ofile.puts(" qt_gsi::qt_release (#{obj});")
ofile.puts(" }");
end
end
def produce_arg_read(ofile, decl_obj, func, alist, kept_args = [])
n_args = func.max_args
@ -2005,6 +2017,7 @@ END
ofile.puts("{")
ofile.puts(" __SUPPRESS_UNUSED_WARNING(args);")
produce_arg_read(ofile, decl_obj, func, alist, conf.kept_args(bd))
produce_keep_self(ofile, alist, "(#{cls} *)cls", conf.owner_args(bd))
if !rt.is_void?
ofile.puts(" ret.write<#{rt.gsi_decl_return(decl_obj)} > ((#{rt.gsi_decl_return(decl_obj)})" + rt.access_gsi_return(decl_obj, "((#{cls} *)cls)->#{mid} (#{qt_alist.join(', ')})") + ");")
else
@ -2615,11 +2628,7 @@ END
produce_arg_read(ofile, decl_obj, func, alist, conf.kept_args(bd))
if conf.owner_args(bd).size > 0
ofile.puts(" #{clsn}_Adaptor *obj = new #{clsn}_Adaptor (#{qt_alist.join(', ')});")
conf.owner_args(bd).each do |a|
ofile.puts(" if (#{alist[a]}) {");
ofile.puts(" qt_gsi::qt_keep (obj);")
ofile.puts(" }");
end
produce_keep_self(ofile, alist, "obj", conf.owner_args(bd))
ofile.puts(" ret.write<#{clsn}_Adaptor *> (obj);")
else
ofile.puts(" ret.write<#{clsn}_Adaptor *> (new #{clsn}_Adaptor (#{qt_alist.join(', ')}));")

View File

@ -465,6 +465,11 @@ static void _call_f_setParent_1302 (const qt_gsi::GenericMethod * /*decl*/, void
__SUPPRESS_UNUSED_WARNING(args);
tl::Heap heap;
QObject *arg1 = gsi::arg_reader<QObject * >() (args, heap);
if (arg1) {
qt_gsi::qt_keep ((QObject *)cls);
} else {
qt_gsi::qt_release ((QObject *)cls);
}
__SUPPRESS_UNUSED_WARNING(ret);
((QObject *)cls)->setParent (arg1);
}

View File

@ -86,6 +86,21 @@ static void _call_f_inputContext_c0 (const qt_gsi::GenericMethod * /*decl*/, voi
}
// bool QApplication::isSessionRestored()
static void _init_f_isSessionRestored_c0 (qt_gsi::GenericMethod *decl)
{
decl->set_return<bool > ();
}
static void _call_f_isSessionRestored_c0 (const qt_gsi::GenericMethod * /*decl*/, void *cls, gsi::SerialArgs &args, gsi::SerialArgs &ret)
{
__SUPPRESS_UNUSED_WARNING(args);
ret.write<bool > ((bool)((QApplication *)cls)->isSessionRestored ());
}
// bool QApplication::notify(QObject *, QEvent *)
@ -108,6 +123,36 @@ static void _call_f_notify_2411 (const qt_gsi::GenericMethod * /*decl*/, void *c
}
// QString QApplication::sessionId()
static void _init_f_sessionId_c0 (qt_gsi::GenericMethod *decl)
{
decl->set_return<QString > ();
}
static void _call_f_sessionId_c0 (const qt_gsi::GenericMethod * /*decl*/, void *cls, gsi::SerialArgs &args, gsi::SerialArgs &ret)
{
__SUPPRESS_UNUSED_WARNING(args);
ret.write<QString > ((QString)((QApplication *)cls)->sessionId ());
}
// QString QApplication::sessionKey()
static void _init_f_sessionKey_c0 (qt_gsi::GenericMethod *decl)
{
decl->set_return<QString > ();
}
static void _call_f_sessionKey_c0 (const qt_gsi::GenericMethod * /*decl*/, void *cls, gsi::SerialArgs &args, gsi::SerialArgs &ret)
{
__SUPPRESS_UNUSED_WARNING(args);
ret.write<QString > ((QString)((QApplication *)cls)->sessionKey ());
}
// void QApplication::setAutoSipEnabled(const bool enabled)
@ -1488,7 +1533,10 @@ static gsi::Methods methods_QApplication () {
methods += new qt_gsi::GenericStaticMethod ("staticMetaObject", "@brief Obtains the static MetaObject for this class.", &_init_smo, &_call_smo);
methods += new qt_gsi::GenericMethod (":autoSipEnabled", "@brief Method bool QApplication::autoSipEnabled()\n", true, &_init_f_autoSipEnabled_c0, &_call_f_autoSipEnabled_c0);
methods += new qt_gsi::GenericMethod (":inputContext", "@brief Method QInputContext *QApplication::inputContext()\n", true, &_init_f_inputContext_c0, &_call_f_inputContext_c0);
methods += new qt_gsi::GenericMethod ("isSessionRestored?", "@brief Method bool QApplication::isSessionRestored()\n", true, &_init_f_isSessionRestored_c0, &_call_f_isSessionRestored_c0);
methods += new qt_gsi::GenericMethod ("notify", "@brief Method bool QApplication::notify(QObject *, QEvent *)\nThis is a reimplementation of QCoreApplication::notify", false, &_init_f_notify_2411, &_call_f_notify_2411);
methods += new qt_gsi::GenericMethod ("sessionId", "@brief Method QString QApplication::sessionId()\n", true, &_init_f_sessionId_c0, &_call_f_sessionId_c0);
methods += new qt_gsi::GenericMethod ("sessionKey", "@brief Method QString QApplication::sessionKey()\n", true, &_init_f_sessionKey_c0, &_call_f_sessionKey_c0);
methods += new qt_gsi::GenericMethod ("setAutoSipEnabled|autoSipEnabled=", "@brief Method void QApplication::setAutoSipEnabled(const bool enabled)\n", false, &_init_f_setAutoSipEnabled_1559, &_call_f_setAutoSipEnabled_1559);
methods += new qt_gsi::GenericMethod ("setInputContext|inputContext=", "@brief Method void QApplication::setInputContext(QInputContext *)\n", false, &_init_f_setInputContext_1972, &_call_f_setInputContext_1972);
methods += new qt_gsi::GenericMethod ("setStyleSheet|styleSheet=", "@brief Method void QApplication::setStyleSheet(const QString &sheet)\n", false, &_init_f_setStyleSheet_2025, &_call_f_setStyleSheet_2025);

View File

@ -1028,6 +1028,8 @@ static void _call_ctor_QListWidgetItem_Adaptor_2386 (const qt_gsi::GenericStatic
QListWidgetItem_Adaptor *obj = new QListWidgetItem_Adaptor (arg1, arg2);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QListWidgetItem_Adaptor *> (obj);
}

View File

@ -1600,6 +1600,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2374 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1628,6 +1630,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4703 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1656,6 +1660,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4380 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1681,6 +1687,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2773 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1709,6 +1717,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_5102 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1737,6 +1747,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4779 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}

View File

@ -2775,6 +2775,7 @@ static void _call_f_setLayout_1341 (const qt_gsi::GenericMethod * /*decl*/, void
__SUPPRESS_UNUSED_WARNING(args);
tl::Heap heap;
QLayout *arg1 = gsi::arg_reader<QLayout * >() (args, heap);
qt_gsi::qt_keep (arg1);
__SUPPRESS_UNUSED_WARNING(ret);
((QWidget *)cls)->setLayout (arg1);
}
@ -3081,6 +3082,11 @@ static void _call_f_setParent_1315 (const qt_gsi::GenericMethod * /*decl*/, void
__SUPPRESS_UNUSED_WARNING(args);
tl::Heap heap;
QWidget *arg1 = gsi::arg_reader<QWidget * >() (args, heap);
if (arg1) {
qt_gsi::qt_keep ((QWidget *)cls);
} else {
qt_gsi::qt_release ((QWidget *)cls);
}
__SUPPRESS_UNUSED_WARNING(ret);
((QWidget *)cls)->setParent (arg1);
}
@ -3104,6 +3110,11 @@ static void _call_f_setParent_3702 (const qt_gsi::GenericMethod * /*decl*/, void
tl::Heap heap;
QWidget *arg1 = gsi::arg_reader<QWidget * >() (args, heap);
QFlags<Qt::WindowType> arg2 = gsi::arg_reader<QFlags<Qt::WindowType> >() (args, heap);
if (arg1) {
qt_gsi::qt_keep ((QWidget *)cls);
} else {
qt_gsi::qt_release ((QWidget *)cls);
}
__SUPPRESS_UNUSED_WARNING(ret);
((QWidget *)cls)->setParent (arg1, arg2);
}

View File

@ -501,6 +501,11 @@ static void _call_f_setParent_1302 (const qt_gsi::GenericMethod * /*decl*/, void
__SUPPRESS_UNUSED_WARNING(args);
tl::Heap heap;
QObject *arg1 = gsi::arg_reader<QObject * >() (args, heap);
if (arg1) {
qt_gsi::qt_keep ((QObject *)cls);
} else {
qt_gsi::qt_release ((QObject *)cls);
}
__SUPPRESS_UNUSED_WARNING(ret);
((QObject *)cls)->setParent (arg1);
}

View File

@ -1028,6 +1028,8 @@ static void _call_ctor_QListWidgetItem_Adaptor_2386 (const qt_gsi::GenericStatic
QListWidgetItem_Adaptor *obj = new QListWidgetItem_Adaptor (arg1, arg2);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QListWidgetItem_Adaptor *> (obj);
}

View File

@ -1600,6 +1600,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2374 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1628,6 +1630,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4703 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1656,6 +1660,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4380 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1681,6 +1687,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2773 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1709,6 +1717,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_5102 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}
@ -1737,6 +1747,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4779 (const qt_gsi::GenericStatic
QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3);
if (arg1) {
qt_gsi::qt_keep (obj);
} else {
qt_gsi::qt_release (obj);
}
ret.write<QTreeWidgetItem_Adaptor *> (obj);
}

View File

@ -2792,6 +2792,7 @@ static void _call_f_setLayout_1341 (const qt_gsi::GenericMethod * /*decl*/, void
__SUPPRESS_UNUSED_WARNING(args);
tl::Heap heap;
QLayout *arg1 = gsi::arg_reader<QLayout * >() (args, heap);
qt_gsi::qt_keep (arg1);
__SUPPRESS_UNUSED_WARNING(ret);
((QWidget *)cls)->setLayout (arg1);
}
@ -3098,6 +3099,11 @@ static void _call_f_setParent_1315 (const qt_gsi::GenericMethod * /*decl*/, void
__SUPPRESS_UNUSED_WARNING(args);
tl::Heap heap;
QWidget *arg1 = gsi::arg_reader<QWidget * >() (args, heap);
if (arg1) {
qt_gsi::qt_keep ((QWidget *)cls);
} else {
qt_gsi::qt_release ((QWidget *)cls);
}
__SUPPRESS_UNUSED_WARNING(ret);
((QWidget *)cls)->setParent (arg1);
}
@ -3121,6 +3127,11 @@ static void _call_f_setParent_3702 (const qt_gsi::GenericMethod * /*decl*/, void
tl::Heap heap;
QWidget *arg1 = gsi::arg_reader<QWidget * >() (args, heap);
QFlags<Qt::WindowType> arg2 = gsi::arg_reader<QFlags<Qt::WindowType> >() (args, heap);
if (arg1) {
qt_gsi::qt_keep ((QWidget *)cls);
} else {
qt_gsi::qt_release ((QWidget *)cls);
}
__SUPPRESS_UNUSED_WARNING(ret);
((QWidget *)cls)->setParent (arg1, arg2);
}

View File

@ -488,6 +488,20 @@ inline void qt_keep (T *obj)
}
}
/**
* @brief An implementation helper for the "keep arg" feature
* This helper will call release on the object, hence returning the
* ownership to the script framework.
*/
template <class T>
inline void qt_release (T *obj)
{
QtObjectBase *qt_obj = dynamic_cast<QtObjectBase *>(obj);
if (qt_obj) {
qt_obj->release ();
}
}
template <class T>
inline void qt_keep (const QList<T *> &list)
{

View File

@ -613,6 +613,66 @@ class QtBinding_TestClass < TestBase
end
def test_46
# Layout becomes owned by widget
w = RBA::QWidget::new
l = RBA::QHBoxLayout::new
w.setLayout(l)
w._destroy
assert_equal(l.destroyed?, true)
end
def test_47
# setParent will attach ownership for QWidget
w = RBA::QWidget::new
wc = RBA::QWidget::new
wc.setParent(w)
w._destroy
assert_equal(wc.destroyed?, true)
end
def test_48
# setParent will attach ownership for QObject
w = RBA::QObject::new
wc = RBA::QObject::new
wc.setParent(w)
w._destroy
assert_equal(wc.destroyed?, true)
end
def test_49
# setParent to nil will release ownership for QObject
w = RBA::QObject::new
wc = RBA::QObject::new
wc.setParent(w)
assert_equal(wc.parent == w, true)
wc.setParent(nil)
w._destroy
assert_equal(wc.destroyed?, false)
wc._destroy
assert_equal(wc.destroyed?, true)
end
end
load("test_epilogue.rb")