Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. "variable" is declared more than once (M107) or "variable" is used before declaration (M105)
Forum Updated to NodeBB v4.3 + New Features

"variable" is declared more than once (M107) or "variable" is used before declaration (M105)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 777 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SyntaXS Offline
    SyntaXS Offline
    SyntaX
    wrote on last edited by
    #1

    Sorry if the title is a bit generic, but I am having trouble iterating arrays correctly :/

    What is the recommend way if I want to iterate multiple array, using the same variable / identifier?

    Showing some example code:

    for (var item of collection) {
        // do stuff with item
    }
    
    for (var item of another_collection) { // Qt creator shows that "item" is declared more than once (M107)
        // do stuff with item
    }
    

    I am not sure about how exactly hoisting works in javascript, but if I try using let instead of var, Qt Creator shows another warning:

    for (let item of collection) {
        // do stuff with item // var "item" is used before its declaration (M105)
    }
    
    for (let item of another_collection) {
        // do stuff with item
    }
    

    Although I didn't run into problems right now, I was wondering, what is the correct way to iterate through multiple lists, using the same identifier?
    Do I really need to use different variables (e.g. item1, item2...) or did I miss something essential here?

    best regards
    SyntaX

    1 Reply Last reply
    1
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      The correct way is as you did with let, the warning printed by Qt Creator is a false positive.

      This has been reported in : https://bugreports.qt.io/browse/QTCREATORBUG-22907

      SyntaXS 1 Reply Last reply
      2
      • GrecKoG GrecKo

        The correct way is as you did with let, the warning printed by Qt Creator is a false positive.

        This has been reported in : https://bugreports.qt.io/browse/QTCREATORBUG-22907

        SyntaXS Offline
        SyntaXS Offline
        SyntaX
        wrote on last edited by
        #3

        @GrecKo Ah nice, good to know, thank you

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved