在main中创建的对象不在QApplication的线程中

时间:2018-08-06 09:55:37

标签: c++ qt qthread

自2天以来,我一直在尝试解决一个问题:

package main

import (
    "fmt"
    "encoding/json"
)

var jsonBytes string = `[["9BC67ACD", "example1", "example1.co.uk", "2018-08-06 08:46:44", "2018-08-06 08:46:44", "2018-08-06 08:46:44", "FINISHED", 1], ["B339CBA2", "example2", "example2.co.uk", "2018-08-06 08:38:25", "2018-08-06 08:38:24", "2018-08-06 08:38:27", "FINISHED", 1]]`

func main() {
    var result interface{}
    if err := json.Unmarshal([]byte(jsonBytes), &result); err != nil{
        fmt.Println(err)
    }
    fetchValue(result) // This function recursively get the underlying value of an interface.
}

func fetchValue(value interface{}) {
    switch value.(type) {
    case string:
        fmt.Printf("%v is an string \n ", value.(string))
    case bool:
        fmt.Printf("%v is bool \n ", value.(bool))
    case float64:
        fmt.Printf("%v is float64 \n ", value.(float64))
    case []interface{}:
        fmt.Printf("%v is a slice of interface \n ", value)
        for _, v := range value.([]interface{}) {
            fetchValue(v)
        }
    case map[string]interface{}:
        fmt.Printf("%v is a map \n ", value)
        for _, v := range value.(map[string]interface{}) {
            fetchValue(v)
        }
    default:
        fmt.Printf("%v is unknown \n ", value)
    }
}

当我在控制台中显示pController线程时:

int main(int argc, char *argv[])
{
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("MacoUV"));

    QApplication app(argc, argv);

    int result;

    MacoUVController * pController = new MacoUVController();

    pController->start();

    result = app.exec();         
    return result;
}

我显示了两个不同的线程地址,我不明白为什么,因为所有对象通常都是在主线程中创建的,除非您将它们明确地移动(例如,使用moveToThread)到另一个线程中。

有关此问题的任何解释吗?

0 个答案:

没有答案