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

QInputDialog_GetText crashes randomly #36

Closed
testhmaa opened this issue May 24, 2016 · 4 comments
Closed

QInputDialog_GetText crashes randomly #36

testhmaa opened this issue May 24, 2016 · 4 comments

Comments

@testhmaa
Copy link

testhmaa commented May 24, 2016

Original define is

QString QInputDialog::getText(QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone)

your definition is

func QInputDialog_GetText(parent QWidget_ITF, title string, label string, mode QLineEdit__EchoMode, text string, ok bool, flags core.Qt__WindowType, inputMethodHints core.Qt__InputMethodHint) string {
    defer qt.Recovering("QInputDialog::getText")

    return C.GoString(C.QInputDialog_QInputDialog_GetText(PointerFromQWidget(parent), C.CString(title), C.CString(label), C.int(mode), C.CString(text), C.int(qt.GoBoolToInt(ok)), C.int(flags), C.int(inputMethodHints)))
}

if you see carefully, the ok bool parameter is a pointer, which causes the application to crash randomly.similiar bug appear in various other forms of QInputDialog.

@therecipe
Copy link
Owner

Hey

I'm aware of that, but all bool* parameters are currently ignored.
If you take a look at the widgets.cpp, you will see that the bool won't make it into the final call.

char* QInputDialog_QInputDialog_GetText(void* parent, char* title, char* label, int mode, char* text, int ok, int flags, int inputMethodHints)
{
    return QInputDialog::getText(static_cast<QWidget*>(parent), QString(title), QString(label), static_cast<QLineEdit::EchoMode>(mode), QString(text), NULL, static_cast<Qt::WindowType>(flags), static_cast<Qt::InputMethodHint>(inputMethodHints)).toUtf8().data();
}

I'm planning to make them usuable (change them from bool to *bool on the go side) and also pass them all the way into the c++ call, but I haven't found time for it yet.

But, I tested the code below and it works for me.

So, could you provide me a snipped of your code, so I can reproduce the problem?

package main

import (
    "os"

    "github.com/therecipe/qt/core"
    "github.com/therecipe/qt/widgets"
)

func main() {
    widgets.NewQApplication(len(os.Args), os.Args)

    var button = widgets.NewQPushButton2("open dialog", nil)

    button.ConnectClicked(func(_ bool) {
        button.SetText(widgets.QInputDialog_GetText(button, "Title", "Label", widgets.QLineEdit__Normal, "Text", false, core.Qt__Dialog, core.Qt__ImhNone))
    })

    button.Show()

    widgets.QApplication_Exec()
}

@testhmaa
Copy link
Author

testhmaa commented May 27, 2016

I have tested it more trying to extract code however as soon as i rip it away from my code base, it starts acting stable.
I tested the code the below code nearly a 100 times and it crashed just once
so i assume the problem is still there.

package main

import (
    "os"
    "fmt"
    "github.com/therecipe/qt/core"
    "github.com/therecipe/qt/widgets"
)


 func main() {

        widgets.NewQApplication(len(os.Args), os.Args)

        var widget = widgets.NewQWidget(nil, 0)

//this crashes because of boolean paramter which should be a pointer
        var u = widgets.QInputDialog_GetText(widget, "title Enter username", "Enter username",
            widgets.QLineEdit__Normal, "", true, core.Qt__Dialog, core.Qt__ImhNone)

        fmt.Printf("user entered %s\n", u) 

}

@5k3105
Copy link
Contributor

5k3105 commented Jun 2, 2016

triple tilde and the word 'go' to get syntax hilight

@therecipe
Copy link
Owner

Hey

I looked into this again and tested the static function QInputDialog::getText manually (100 times), but it didn't crash.
And I also used the code below to test if a manually created QInputDialog would crash, but it didn't.

I'm using go1.7beta1 darwin/amd64, OS X 10.11.5 and Qt 5.7

Please try to find an example which crashes more often.

package main

import (
    "fmt"
    "os"
    "time"

    "github.com/therecipe/qt/core"
    "github.com/therecipe/qt/widgets"
)

func main() {
    widgets.NewQApplication(len(os.Args), os.Args)

    var widget = widgets.NewQWidget(nil, 0)

    for i := 0; i < 200; i++ {

        var dialog = widgets.NewQInputDialog(widget, core.Qt__Dialog)
        dialog.SetWindowTitle("title Enter username")
        dialog.SetLabelText("Enter username")
        dialog.SetTextEchoMode(widgets.QLineEdit__Normal)
        dialog.SetInputMethodHints(core.Qt__ImhNone)

        dialog.ConnectAccept(func() {
            fmt.Printf("user entered %s\n", dialog.TextValue())
            dialog.AcceptDefault()
        })

        go func() {
            time.Sleep(25 * time.Millisecond)

            dialog.SetTextValue(fmt.Sprint(i))

            dialog.Accept()
        }()

        dialog.Exec()
    }
}

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

3 participants