Unsolved Novice: where is “key” defined
-
I am a newbie with QT, the only one using it, and on a critical project with a need to modify existing code.
Looking through some of the qml files we have is code to the effect:
Sometab = newTab( xxx )
Looking through the QT web pages I cannot find method NewTab. I am probably in solid ground in presuming what it does, but want to read about it.In another passage are multiple instances of:
If( key === <something> )
The variable “key” is not defined in the code. Having never seen the triple equal I searched that and did find that it is a strict equality. That means, to my estimation, that key cannot be an untyped variable. But it is not defined. Have I provided sufficient information to provide for an answer?
Note: I am doing this from home because this forum would not send a verification email to my government address. Anyone have any idea as to what is up with that? The email domain is: us.af.mil. There are five dots in my email so maybe that is a problem. Therefore, I don’t have full details. Now that I have an account from home I will be able to access this tomorrow and provide additional needed details
-
@BKBK said in Novice: where is “key” defined:
The variable “key” is not defined in the code.
in WHAT code?
-
Yes, I was not clear. I am looking in file main.qml and trying to figure out what it is doing. There are 20 some files referenced and I have looked in each of them and searched for the phrase: key. In each file the first usage is this, or very close to it:
if ( key === Qt.Key_Tab)
The use of triple = character suggests that key is not an automatically created variable because the first thing that === checks for is type identify. If the two items being compare are not identical type a False is returned.
In all occurrences of "key" in the code it is on the left side of the ===. I find no declaration. In all places it is to the left of the ===. I see no place where a value is assigned to it.
Is "key" a keyword or something of that sort, meaning is it a pre-defined variable that is always present? -
@BKBK
I suspect you mean the parameter of a signal maybe, but for an proper answer you should show more than one line of code, or at least post a link to the example/code you are referring to. -
Hi @BKBK ,
@BKBK said in Novice: where is “key” defined:
Looking through some of the qml files we have is code to the effect:
Sometab = newTab( xxx )
Looking through the QT web pages I cannot find method NewTab.AFAIK, Qt does not have anything called "newTab" or "NewTab". (Also, be careful: C++ and QML code are case sensitive)
I suspect it's a custom method defined in your project itself.
Note: I am doing this from home because this forum would not send a verification email to my government address. Anyone have any idea as to what is up with that?
Perhaps the military server blocks emails from untrusted sources? Or perhaps the email landed in your junk mail folder?
@BKBK said in Novice: where is “key” defined:
The use of triple = character suggests that key is not an automatically created variable because the first thing that === checks for is type identify.
I wouldn't jump to that conclusion. There's nothing to stop someone from using
===
with automatically created variables. Perhaps the original author was just following best practices.Often, either
==
or===
will get the job done, so people can just choose the "safe" option and use===
everywhere in their code, even when it's not strictly necessary.Is "key" a keyword or something of that sort, meaning is it a pre-defined variable that is always present?
I haven't seen
key
used in isolation before, from built-in Qt types. The closest I know of isevent.key
(whereevent
is a variable of theKeyEvent
type): http://doc.qt.io/qt-5/qml-qtquick-keyevent.htmlIn all occurrences of "key" in the code it is on the left side of the ===. I find no declaration. In all places it is to the left of the ===. I see no place where a value is assigned to it.
It is difficult for us to understand your code from these isolated descriptions alone. If possible, please post an actual snippet that shows us the context of where
key
is used -- the surrounding code might contain useful clues you haven't noticed. However, given that this is a military project, I'd understand if you cannot divulge the code.At the very least, please tell us what the entire JavaScript block is attached to. Who "owns" the block of code which contains
if ( key === Qt.Key_Tab)
? For example, in the QML below, the JavaScript block is attached toKeys.onPressed
:Item { focus: true Keys.onPressed: { if ((event.key == Qt.Key_Enter) && (event.modifiers & Qt.ShiftModifier)) doSomething(); } }