Login  Register

Re: Inputting Line with specified length (Ortho)

Posted by TimzPilot on May 17, 2023; 10:53pm
URL: https://forum.librecad.org/Inputting-Line-with-specified-length-Ortho-tp5722807p5722815.html

When I dared to try ChatGPT to create a Qt code in an attempt to perform as per above subject.  Here is the code:

#include <QtWidgets>

class LineLengthDialog : public QDialog
{
    Q_OBJECT

public:
    explicit LineLengthDialog(QWidget *parent = nullptr)
        : QDialog(parent)
    {
        // Create the line edit widget
        lineEdit = new QLineEdit(this);

        // Create the OK and Cancel buttons
        QPushButton *okButton = new QPushButton("OK", this);
        QPushButton *cancelButton = new QPushButton("Cancel", this);

        // Create the layout
        QHBoxLayout *layout = new QHBoxLayout;
        layout->addWidget(lineEdit);
        layout->addWidget(okButton);
        layout->addWidget(cancelButton);

        // Set the layout for the dialog
        setLayout(layout);

        // Connect the button signals to slots
        connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
        connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);

        setWindowTitle("Enter Line Length");
    }

    QString getLineLength()
    {
        return lineEdit->text();
    }

private:
    QLineEdit *lineEdit;
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    LineLengthDialog dialog;
    if (dialog.exec() == QDialog::Accepted) {
        QString lineLength = dialog.getLineLength();
        // Use the entered line length as needed
        qDebug() << "Line length entered: " << lineLength;
    }

    return app.exec();
}

#include "main.moc"

Then ChatGPT says the following comments:

This code creates a custom dialog (LineLengthDialog) with a line edit (QLineEdit) for the user to enter the line length. It also includes OK and Cancel buttons. When the user clicks the OK button, the entered line length is retrieved from the line edit and can be used as needed.

Please note that this is just a basic example, and you may need to adapt it to integrate with LibreCAD based on your specific requirements.

++ END


No Idea whether this would work or not as I'm no expert on Qt programming.  Anyone out there to try it out or is ChatGPT unreliable?