Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Crash on opening file #11

Closed
fuchsmich opened this issue Apr 18, 2017 · 5 comments
Closed

Windows: Crash on opening file #11

fuchsmich opened this issue Apr 18, 2017 · 5 comments

Comments

@fuchsmich
Copy link

fuchsmich commented Apr 18, 2017

10:52:28.601 [qtodotxt.lib.file] DEBUG: Setting up FileObserver instance.
qml: OPENING file:///C:/Users/mfuchs/qtprojects/QTodoTxt2/examples/todo.txt
10:52:43.415 [qtodotxt.controllers.main_controller] DEBUG: MainController.open c
alled with filename="//C:/Users/mfuchs/qtprojects/QTodoTxt2/examples/todo.txt"
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\mfuchs\qtprojects\QTodoTxt2\bin\..\qtodotxt\controllers\main_co
ntroller.py", line 249, in open
    self._file.load(filename)
  File "C:\Users\mfuchs\qtprojects\QTodoTxt2\bin\..\qtodotxt\lib\file.py", line
30, in load
    with open(filename, 'rt', encoding='utf-8') as fd:
OSError: [Errno 22] Invalid argument: '//C:/Users/mfuchs/qtprojects/QTodoTxt2/ex
amples/todo.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mfuchs\AppData\Local\Programs\Python\Python36-32\lib\logging\__
init__.py", line 992, in emit
    msg = self.format(record)
  File "C:\Users\mfuchs\AppData\Local\Programs\Python\Python36-32\lib\logging\__
init__.py", line 838, in format
    return fmt.format(record)
  File "C:\Users\mfuchs\AppData\Local\Programs\Python\Python36-32\lib\logging\__
init__.py", line 575, in format
    record.message = record.getMessage()
  File "C:\Users\mfuchs\AppData\Local\Programs\Python\Python36-32\lib\logging\__
init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "C:\Users\mfuchs\qtprojects\QTodoTxt2\bin\qtodotxt.pyw", line 30, in <mod
ule>
    app.run()
  File "C:\Users\mfuchs\qtprojects\QTodoTxt2\bin\..\qtodotxt\app.py", line 113,
in run
    app.exec_()
  File "C:\Users\mfuchs\qtprojects\QTodoTxt2\bin\..\qtodotxt\controllers\main_co
ntroller.py", line 251, in open
    self.showError(self.tr("Error opening file: {}.\n Exception:{}").format(file
name, ex))
  File "C:\Users\mfuchs\qtprojects\QTodoTxt2\bin\..\qtodotxt\controllers\main_co
ntroller.py", line 47, in showError
    logger.debug("ERROR", msg)
Message: 'ERROR'
Arguments: ("Error opening file: //C:/Users/mfuchs/qtprojects/QTodoTxt2/examples
/todo.txt.\n Exception:[Errno 22] Invalid argument: '//C:/Users/mfuchs/qtproject
s/QTodoTxt2/examples/todo.txt'",)
qml: And of course you could only agree.
@fuchsmich
Copy link
Author

Does it help, if we use url / QUrl when passing the filename from qml to python?

http://doc.qt.io/qt-5/qtqml-cppintegration-data.html

@oroulet
Copy link
Contributor

oroulet commented Apr 18, 2017

yes pass a Qurl object. I will have a look.

@fuchsmich
Copy link
Author

With this opening the file works.

maincontroller Line 243:

    @QtCore.pyqtSlot('QUrl')
    def open(self, fileUrl):
        filename = fileUrl.toLocalFile()

But internally open is called with a string (e.g. on next start of the program).
So maybe we need a wrapper for the slot, which is called from qml. Like:

    @QtCore.pyqtSlot('QUrl')
    def openFromGui(self, fileUrl):
        self.open(fileUrl.toLocalFile())

@oroulet
Copy link
Contributor

oroulet commented Apr 18, 2017

I propose method overload

@QtCore.pyqtSlot('QUrl')
@QtCore.pyqtSlot(str)
def open(self, path):

or @QtCore.pyqtSlot(QVariant)

and add test in Python

  if isintance(path, QUrl):
    path = path.toLocaleFile()

@oroulet
Copy link
Contributor

oroulet commented Apr 18, 2017

hopefully fixed now

@oroulet oroulet closed this as completed Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants