Unsolved Calling a variable from C++ in QML
-
Pro (QtCreator) tip:
write
Q_PROPERTY(QString pNumber READ pNumber WRITE setPNumber NOTIFY pNumberChanged)
right click on
Q_PROPERTY
selectRefactor
click onGenerate Missing Q_Property Members
saves a lot of time
-
Great thank you,
but i still have this problem, that i cannot read the value in QML when i write this:
console.log (thepnumber.pNumber)
it shows nothing
-
@mamoud said in Calling a variable from C++ in QML:
Great thank you,
but i still have this problem, that i cannot read the value in QML when i write this:
console.log (thepnumber.pNumber)
it shows nothing
more context please, where exactly is this called?
//General solution
Connections{
target: thepnumberonpNumberChanged: console.log(thepnumber.pNumber)
} -
I have a QML called PageInfo.qml
Rectangle { id: infopage function pageEnter() { console.log("The part is: " + thepnumber.pNumber) }
-
-
Once i enter this page it will be called
-
@mamoud
if you writefunction pageEnter() {
console.log("Enter Function to get Number")
console.log("The part is: " + thepnumber.pNumber)
}do you see any console logs?
-
Did you set a value to
m_pNumber
? if you never assign anything to it than it's totally natural that the log shows an empty string. -
Yeah i see
Enter Function to get Number
and also i see
The part is:
but no value is shown for thepnumber.pNumber -
No but this m_pNumber should get values from a CAN signal (canalyzer) which is set in .cpp file