1

I created a project in QGIS 3.14 to export to Qfield. Collected data and tried synching with the project on my laptop. After numerous attempts, I updated to the latest, stable version of QGIS and used QField sync v.4.0.0 to try to sync the data once more. The data appears on the map but I got the following error message;

IndexError: list index out of range 
Traceback (most recent call last):
  File "C:\Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qfieldsync\libqfieldsync\offline_converter.py", 
    line 561, in on_offline_editing_next_layer
    layer_name=self.__offline_layer_names[layer_index - 1]
IndexError: list index out of range


Python version: 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] 
QGIS version: 3.16.8-Hannover Hannover, 8c50902e 

Python Path:
C:/PROGRA~1/QGIS31~1.8/apps/qgis-ltr/./python
C:/Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA~1/QGIS31~1.8/apps/qgis-ltr/./python/plugins
C:\Program Files\QGIS 3.16.8\bin\python39.zip
C:\PROGRA~1\QGIS31~1.8\apps\Python39\DLLs
C:\PROGRA~1\QGIS31~1.8\apps\Python39\lib
C:\Program Files\QGIS 3.16.8\bin
C:\PROGRA~1\QGIS31~1.8\apps\Python39
C:\PROGRA~1\QGIS31~1.8\apps\Python39\lib\site-packages
C:\PROGRA~1\QGIS31~1.8\apps\Python39\lib\site-packages\win32
C:\PROGRA~1\QGIS31~1.8\apps\Python39\lib\site-packages\win32\lib
C:\PROGRA~1\QGIS31~1.8\apps\Python39\lib\site-packages\Pythonwin
C:/Users/User/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\DigitizingTools\tools
C:\Users\User\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\DigitizingTools
C:/Users/User/Documents/Qfield_import
4
  • 1
    Your error is in the trace dump, you are attempting at access an element in your list that doesn't exist. I cannot see enough of the code to be sure what you are doing, but check your edge cases, are you sure you need to subtract one? Python uses zero index. Considering using for ... range() loops, it is a bit more concise and avoids out-of-bounds.
    – RomaH
    Jul 13 at 16:10
  • @RomaH thank you for your answer. I'm a bit of a novice, how do I check my edge cases? And how do I go about using for range () loops?
    – user188161
    Jul 14 at 10:00
  • Edge cases is a catch-all for any scenario that might be rare but your code will have to deal with. You code may work for an array with 100 items, as you intended when you wrote it, but what will it do with an empty array or an array with millions of item? It simply means thinking up those scenarios and coding to handle those exceptions: code it to handle it without any problem or halt and notify the user.
    – RomaH
    Jul 14 at 13:14
  • For the range() loops, look at this page, it is the most friendly. w3schools.com/python/python_for_loops.asp Simply put, change your for loop if you are using loops, to: for i in range(self._offline_layer_names): print(i)
    – RomaH
    Jul 14 at 13:21

Browse other questions tagged or ask your own question.