I want to save my layout. I've tried this solution but and it worked. The file is created but when I try to open it, it doesn't work. I don't know why.
Here is my code:
project = QgsProject.instance()
manager = project.layoutManager()
layout = QgsPrintLayout(project)
layout.initializeDefaults()
layout.setName(layoutName)
manager.addLayout(layout)
pc = layout.pageCollection()
page = pc.pages()[0]
page.setPageSize(pageSize, QgsLayoutItemPage.Orientation.Landscape)
layout_view = open_designer.view()
layout.saveAsTemplate('C:/Users/ilyasse2.0/Desktop/SQRLAND/layout.qpt',QgsReadWriteContext())
The error I get is :
Invalid Data Source: C:\Users\ilyasse2.0\Desktop\SQRLAND\layout.qpt is not a valid or recognized data source.