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

Calling KeyPressEvent for a QLineEdit instance results in a seg fault. #104

Closed
pekim opened this issue Nov 14, 2016 · 4 comments
Closed

Comments

@pekim
Copy link
Contributor

pekim commented Nov 14, 2016

This is fine when Up or Down is pressed. But if anything else is pressed something goes horribly wrong when calling KeyPressEvent. Segmentation fault (core dumped)

	filterEdit := widgets.NewQLineEdit(nil)
	filterEdit.ConnectKeyPressEvent(func(event *gui.QKeyEvent) {
		if event.Key() == int(core.Qt__Key_Down) {
			fmt.Println("down")
		} else if event.Key() == int(core.Qt__Key_Up) {
			fmt.Println("up")
		} else {
			filterEdit.KeyPressEvent(event)
		}
	})

In C++ this works.

void ConversationFilterEdit::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Up){
        emit up();
    }
    else if(event->key() == Qt::Key_Down){
        emit down();
    }
    else{
        QLineEdit::keyPressEvent(event);
    }
}
@pekim
Copy link
Contributor Author

pekim commented Nov 14, 2016

Thinking about it perhaps I'm not on the gui thread, and I need to use a slot. I'll try that.

@pekim
Copy link
Contributor Author

pekim commented Nov 14, 2016

No, that's rubbish. I'm tired and going to bed. I'll come back to it tomorrow.

@therecipe
Copy link
Owner

therecipe commented Nov 14, 2016

Hey

It's a SIGTRAP: trace trap (infinite recursive call in this case)

You probably want to suffix filterEdit.KeyPressEvent with Default to get the same effect like QLineEdit::keyPressEvent in C++.

So this should work:

    filterEdit := widgets.NewQLineEdit(nil)
    filterEdit.ConnectKeyPressEvent(func(event *gui.QKeyEvent) {
        if event.Key() == int(core.Qt__Key_Down) {
            fmt.Println("down")
        } else if event.Key() == int(core.Qt__Key_Up) {
            fmt.Println("up")
        } else {
            filterEdit.KeyPressEventDefault(event)
        }
    })

@pekim
Copy link
Contributor Author

pekim commented Nov 15, 2016

Yes, that works. Thank you.

There are several little nuggets like this that are not easy to discover. I have some thoughts on documentation, and I'll probably open an issue next weekend to discuss.

@pekim pekim closed this as completed Nov 15, 2016
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