mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00
C++: fix including the generated file in several translation units
This commit is contained in:
parent
155b1443e2
commit
81cb89d374
8 changed files with 76 additions and 1 deletions
|
@ -49,6 +49,8 @@ target_link_libraries(test_eventloop PRIVATE Threads::Threads)
|
||||||
slint_test(models)
|
slint_test(models)
|
||||||
slint_test(window)
|
slint_test(window)
|
||||||
|
|
||||||
|
add_subdirectory(multiple-includes)
|
||||||
|
|
||||||
if(SLINT_FEATURE_EXPERIMENTAL)
|
if(SLINT_FEATURE_EXPERIMENTAL)
|
||||||
if(Qt6_FOUND)
|
if(Qt6_FOUND)
|
||||||
add_subdirectory(manual/platform_qt)
|
add_subdirectory(manual/platform_qt)
|
||||||
|
|
7
api/cpp/tests/multiple-includes/CMakeLists.txt
Normal file
7
api/cpp/tests/multiple-includes/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||||
|
|
||||||
|
add_executable(multiple-includes main.cpp logic.cpp)
|
||||||
|
target_link_libraries(multiple-includes PRIVATE Slint::Slint)
|
||||||
|
slint_target_sources(multiple-includes appwindow.slint)
|
||||||
|
|
1
api/cpp/tests/multiple-includes/README.md
Normal file
1
api/cpp/tests/multiple-includes/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This is a test making sure that the header can be included in several file without causing multiple definitions
|
35
api/cpp/tests/multiple-includes/appwindow.slint
Normal file
35
api/cpp/tests/multiple-includes/appwindow.slint
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||||
|
|
||||||
|
import {Button, AboutSlint} from "std-widgets.slint";
|
||||||
|
|
||||||
|
export global Logic {
|
||||||
|
callback increment(int) -> int;
|
||||||
|
}
|
||||||
|
|
||||||
|
export struct FooBar {
|
||||||
|
abc: int, def: string
|
||||||
|
}
|
||||||
|
|
||||||
|
component R {
|
||||||
|
property <FooBar> foo;
|
||||||
|
Rectangle {
|
||||||
|
TouchArea {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export component App inherits Window {
|
||||||
|
preferred-width: 800px;
|
||||||
|
preferred-height: 600px;
|
||||||
|
property <int> count;
|
||||||
|
|
||||||
|
VerticalLayout {
|
||||||
|
AboutSlint { }
|
||||||
|
Button {
|
||||||
|
text: "Hello";
|
||||||
|
clicked => { count = Logic.increment(count); }
|
||||||
|
}
|
||||||
|
Text { text: count; }
|
||||||
|
R { }
|
||||||
|
}
|
||||||
|
}
|
10
api/cpp/tests/multiple-includes/logic.cpp
Normal file
10
api/cpp/tests/multiple-includes/logic.cpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||||
|
|
||||||
|
#include "logic.h"
|
||||||
|
#include "appwindow.h"
|
||||||
|
|
||||||
|
void setup_logic(const Logic &logic)
|
||||||
|
{
|
||||||
|
logic.on_increment([](int x) { return x + 1; });
|
||||||
|
}
|
8
api/cpp/tests/multiple-includes/logic.h
Normal file
8
api/cpp/tests/multiple-includes/logic.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct Logic;
|
||||||
|
|
||||||
|
void setup_logic(const Logic &);
|
12
api/cpp/tests/multiple-includes/main.cpp
Normal file
12
api/cpp/tests/multiple-includes/main.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||||
|
|
||||||
|
#include "logic.h"
|
||||||
|
#include "appwindow.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
auto my_ui = App::create();
|
||||||
|
setup_logic(my_ui->global<Logic>());
|
||||||
|
my_ui->run();
|
||||||
|
}
|
|
@ -1136,7 +1136,7 @@ fn generate_item_tree(
|
||||||
));
|
));
|
||||||
|
|
||||||
file.definitions.push(Declaration::Var(Var {
|
file.definitions.push(Declaration::Var(Var {
|
||||||
ty: "const slint::private_api::ComponentVTable".to_owned(),
|
ty: "inline const slint::private_api::ComponentVTable".to_owned(),
|
||||||
name: format!("{}::static_vtable", item_tree_class_name),
|
name: format!("{}::static_vtable", item_tree_class_name),
|
||||||
init: Some(format!(
|
init: Some(format!(
|
||||||
"{{ visit_children, get_item_ref, get_subtree_range, get_subtree_component, \
|
"{{ visit_children, get_item_ref, get_subtree_range, get_subtree_component, \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue