[Interest] Myanmar-QWERTY crashes OS X application
Timothy W. Grove
tim_grove at sil.org
Sun Aug 28 00:49:39 CEST 2016
Let's see if the formatting is any better this time...
Below is my progress thus far. I've created a simple app with two
QPlainTextEdit's. The only thing else it does is to print out the name
of the keyboard input source associated with a QPlainTextEdit when you
click into it. I'm unsure how to translate the python code for changing
the keyboard into C++ but I've added comments to the
"MainWindow::changeKeyboard" method below to show my approach in python.
Any help or suggestions would be most welcome.
Best regards,
Tim
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPlainTextEdit>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
void changeKeyboard(QVariant keyboard);
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
QWidget *mainWidget;
QPlainTextEdit *textEdit1;
QPlainTextEdit *textEdit2;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include <QWidget>
#include <QVBoxLayout>
#include <QPlainTextEdit>
#include <QObject>
#include <QEvent>
#include <QDebug>
#include "mainwindow.h"
#include "Windows.h"
MainWindow::MainWindow()
{
mainWidget = new QWidget;
setCentralWidget(mainWidget);
QVBoxLayout *layout = new QVBoxLayout;
textEdit1 = new QPlainTextEdit;
textEdit1->setProperty("keyboard", 0x00000809); // British(Windows)
textEdit2 = new QPlainTextEdit;
textEdit2->setProperty("keyboard", 0x00010C00); // Myanmar(Windows)
layout->addWidget(textEdit1);
layout->addWidget(textEdit2);
mainWidget->setLayout(layout);
textEdit1->installEventFilter(this);
textEdit2->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == textEdit1 || obj == textEdit2) {
if (event->type() == QEvent::FocusIn) {
changeKeyboard(obj->property("keyboard"));
}
}
return QMainWindow::eventFilter(obj, event);
}
void MainWindow::changeKeyboard(QVariant keyboard)
{
qDebug() << keyboard.toString();
/* The following is how I did this in Python but I am unsure how to
translate this into C++.
A different approach in C++ would be okay, but it needs to be an
approach I can translate
back into Python/PyQt.
from Cocoa import NSTextInputContext //This line goes at top of
page with any other import statements
ic = NSTextInputContext.currentInputContext()
if not ic:
ic = NSTextInputContext.new()
ic.setValue_forKey_(keyboard.toString(), 'selectedKeyboardInputSource')
*/
}
On 19/08/2016 16:48, timur.kristof at gmail.com wrote:
> Can you create a simple example app without Python, to see if it really is Qt's fault?
>
> (Just create an app with Qt Creator and run it. As far as I understand, you use QWidgets, right? If so, create an empty QWitgets project, run and see how it goes.)
>
> On Fri Aug 19 13:33:58 2016 GMT+0200, Timothy W. Grove wrote:
>> Changing the keyboard input source on OS X back and forth between
>> 'British' and 'Myanmar-QWERTY' crashes my PyQt v5.7 application after
>> about three changes, usually corrupting an attached sqlite database as
>> well. 'Myanmar-QWERTY' is the only input source that I'm having trouble
>> with; all others that I've tested so far appear okay. The windows
>> version of the application also seems okay. My application is fairly
>> complex, but I'm seeing this issue even with an absolute minimal app
>> containing only one window. I'm not certain if the issue is with PyQt or
>> Qt or the input source itself, but it doesn't appear to be with python
>> as a Tkinter app worked okay.
>>
>> Any answers would be great, but if anyone could suggest where to find a
>> solution that would also be helpful. This is a pretty obscure bug, but
>> finding a solution or work-around is important to the application I'm
>> developing. Thank you.
>>
>> Best regards,
>> Timothy Grove
>>
>>
>> Test program:
>>
>> #!/usr/bin/env python3
>> # -*- coding: utf-8 -*-
>>
>> import sys
>> from PyQt5.QtWidgets import QMainWindow
>> from PyQt5.QtWidgets import QTextEdit
>> from PyQt5.QtWidgets import QApplication
>>
>> class MainWindow(QMainWindow):
>> def __init__(self, parent=None):
>> super(MainWindow, self).__init__(parent)
>>
>> text = QTextEdit()
>> self.setCentralWidget(text)
>>
>> if __name__ == "__main__":
>> app = QApplication(sys.argv)
>>
>> mw = MainWindow()
>> mw.show()
>>
>> sys.exit(app.exec_())
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
More information about the Interest
mailing list