Skip to content

Commit b89e5bc

Browse files
committed
Workaround issue #84 (QTBUG-41193).
Closes #84.
1 parent 6b4ad68 commit b89e5bc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

qml.go

+6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ func (e *Engine) Load(location string, r io.Reader) (Object, error) {
9999
}
100100
location = "file:///" + filepath.ToSlash(filepath.Join(dir, location))
101101
}
102+
}
102103

104+
// Workaround issue #84 (QTBUG-41193) by not refering to an existent file.
105+
if s := strings.TrimPrefix(location, "file:///"); s != location {
106+
if _, err := os.Stat(filepath.FromSlash(s)); err == nil {
107+
location = location + "."
108+
}
103109
}
104110

105111
cdata, cdatalen := unsafeBytesData(data)

qml_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"gopkg.in/qml.v1"
2020
"gopkg.in/qml.v1/cpptest"
2121
"gopkg.in/qml.v1/gl/2.0"
22+
"path/filepath"
2223
)
2324

2425
func init() { qml.SetupTesting() }
@@ -336,6 +337,34 @@ func (s *S) TestRegisterConverterPlainObject(c *C) {
336337
c.Assert(calls, Equals, 3)
337338
}
338339

340+
func (s *S) TestIssue84(c *C) {
341+
// Regression test for issue #84 (QTBUG-41193).
342+
data := `
343+
import QtQuick 2.0
344+
Item {
345+
id: item
346+
property string s1: "<before>"
347+
property string s2: "<after>"
348+
states: State {
349+
name: "after";
350+
PropertyChanges { target: item; s1: s2 }
351+
}
352+
Component.onCompleted: state = "after"
353+
}
354+
`
355+
filename := filepath.Join(c.MkDir(), "file.qml")
356+
err := ioutil.WriteFile(filename, []byte(data), 0644)
357+
c.Assert(err, IsNil)
358+
359+
component, err := s.engine.LoadString(filename, data)
360+
c.Assert(err, IsNil)
361+
362+
root := component.Create(nil)
363+
defer root.Destroy()
364+
365+
c.Assert(root.String("s1"), Equals, "<after>")
366+
}
367+
339368
type TestData struct {
340369
*C
341370
engine *qml.Engine

0 commit comments

Comments
 (0)