Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Automating tasks in Qt Creator

var editor = editors.current()
var start = editor.createMark()

editor.gotoPosition(editor.currentFunction.start)
editor.find("{")

var startOfFunction = editor.position()
editor.gotoBlockEnd()
editor.gotoLineStart();
editor.insert("*/\n")
editor.gotoPosition(startOfFunction)
editor.insert("\n/*")

editor.gotoPosition(start)
function main() {
    message.log("This is a log line: message.log(...)")
}
import QtQml 2.2
import Script 1.0

Script {
    property var mark

    function init() {
        mark = editor.createMark()
        editor.gotoDocumentStart()
        editor.insert("/****************************************************************************\n")
        editor.insert("/* Copyright (C) " + Qt.formatDate(new Date(), "yyyy") + " Klaralvdalens Datakonsult AB. All rights reserved.\n")
        editor.insert("** This file is part of the ACME project.")
        editor.insert("\n**********************************************************************/\n\n")
        m.restore()
        Qt.quit()
    }
    TextEditor {
        id: editor
        fileName: Editors.currentFileName
    }
    Component.onCompleted: init()
}
import QtQml 2.2
import Script 1.0
TextEditor {
    id: editor
    fileName: Util.mktemp("foo_XXXXXX.txt")

    KeyHandler {
        key: Qt.Key_Left
        filter: true
        onKeyPressed: doSomething()
    }
    MouseHandler {
        onClicked: doSomethingElse()
    }
    // ...
}

About KDAB


9 Comments

23 - May - 2020

Bela TOTH

25 - May - 2020

Nicolas Arnaud-Cormos

2 - Apr - 2021

Serg

7 - Apr - 2021

Nicolas Arnaud-Cormos

23 - May - 2020

Konstantin

25 - May - 2020

Nicolas Arnaud-Cormos

25 - Jun - 2020

E

26 - Jun - 2020

Nicolas Arnaud-Cormos

30 - Sept - 2020

Luuk

NicolasArnaud-Cormos

Nicolas Arnaud-Cormos

Senior Software Engineer & Teamlead