QtDesigner and C++ Help



  • Hi,
    I am fairly new to Qt. I am having an issue producing the relevant C++ code for a GUI created using QtDesigner.

    The reason I must use QtDesigner and not QtCreator is that I need to use the QTango widgets for Tango control system and I believe they only come with QtDesigner.

    I produced the ui_mydialog.h file by calling uic on the .ui file but not much more. I have tried to create the main.cpp but I am receiving errors such as undefined reference to QApplication...etc even though I have put the path to QApplication in the include path. I am not sure how to create the makefile for this project.

    Has anyone had similar issues or have experience with this? Any help is greatly appreciated. Thanks

    ui_mydialog.h
    @
    #ifndef DIALOG_H
    #define DIALOG_H

    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QDialog>
    #include <QtGui/QHeaderView>
    #include <QtGui/QLabel>
    #include <QtGui/QPushButton>
    #include <QtGui/QTextEdit>
    //#include "TPixmap"

    //#include "taurus.qt.qtgui.display"
    //#include "taurus.qt.qtgui.extra_guiqwt"

    QT_BEGIN_NAMESPACE

    class Ui_MyDialog : public QDialog
    {
    public:
    QLabel *width_label;
    QLabel *height_label;
    QLabel *fps_label;
    QLabel *refresh_rate_label;
    QLabel *params_label;
    QLabel *depth_label;
    QPushButton *apply_button;
    QTextEdit *refresh_rate_textEdit;
    QTextEdit *width_textEdit;
    QTextEdit *height_textEdit;
    QTextEdit *depth_textEdit;
    QTextEdit *fps_textEdit;
    //QPixmapWidget *qPixmapWidget;
    //TaurusImageDialog *imageDialog;
    QLabel *ref_rate_disp;
    //TPixmap *pixmap_display;

    void setupUi(QDialog *Dialog)
    {
        if (Dialog->objectName().isEmpty())
            Dialog->setObjectName(QString::fromUtf8("Dialog"));
        Dialog->resize(909, 354);
        params_label = new QLabel(Dialog);
        params_label->setObjectName(QString::fromUtf8("params_label"));
        params_label->setGeometry(QRect(490, 140, 181, 21));
        depth_label = new QLabel(Dialog);
        depth_label->setObjectName(QString::fromUtf8("depth_label"));
        depth_label->setGeometry(QRect(450, 230, 67, 21));
        apply_button = new QPushButton(Dialog);
        apply_button->setObjectName(QString::fromUtf8("apply_button"));
        apply_button->setGeometry(QRect(810, 280, 61, 21));
        refresh_rate_textEdit = new QTextEdit(Dialog);
        refresh_rate_textEdit->setObjectName(QString::fromUtf8("refresh_rate_textEdit"));
        refresh_rate_textEdit->setGeometry(QRect(690, 280, 101, 21));
        depth_textEdit = new QTextEdit(Dialog);
        depth_textEdit->setObjectName(QString::fromUtf8("depth_textEdit"));
        depth_textEdit->setGeometry(QRect(570, 230, 101, 21));
        fps_textEdit = new QTextEdit(Dialog);
        fps_textEdit->setObjectName(QString::fromUtf8("fps_textEdit"));
        fps_textEdit->setGeometry(QRect(570, 260, 101, 21));
        ref_rate_disp = new QLabel(Dialog);
        ref_rate_disp->setObjectName(QString::fromUtf8("ref_rate_disp"));
        ref_rate_disp->setGeometry(QRect(690, 310, 111, 21));
    
        retranslateUi(Dialog);
    
        QMetaObject::connectSlotsByName(Dialog);
    } // setupUi
    
    void retranslateUi(QDialog *Dialog)
    {
        Dialog->setWindowTitle(QApplication::translate("Dialog", "Camera Interface - Python  (Paul Mulligan)", 0, QApplication::UnicodeUTF8));
        width_label->setText(QApplication::translate("Dialog", "Image width", 0, QApplication::UnicodeUTF8));
        height_label->setText(QApplication::translate("Dialog", "Image height", 0, QApplication::UnicodeUTF8));
        fps_label->setText(QApplication::translate("Dialog", "FPS", 0, QApplication::UnicodeUTF8));
        refresh_rate_label->setText(QApplication::translate("Dialog", "Refresh rate [ms]", 0, QApplication::UnicodeUTF8));
        params_label->setText(QApplication::translate("Dialog", "Camera Parameters", 0, QApplication::UnicodeUTF8));
        depth_label->setText(QApplication::translate("Dialog", "Bit depth", 0, QApplication::UnicodeUTF8));
        apply_button->setText(QApplication::translate("Dialog", "Apply", 0, QApplication::UnicodeUTF8));
        ref_rate_disp->setText(QString());
    } // retranslateUi
    

    };

    namespace Ui {
    class MyDialog: public Ui_MyDialog {};
    } // namespace Ui

    QT_END_NAMESPACE

    #endif // DIALOG_H

    @

    main.cpp
    @
    #include <QtGui/QApplication>
    #include "ui_mydialog.h"

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

    Ui::MyDialog d;
    app.setMainWidget(&d);
    d.show();
    
    int rec = app.exec&#40;&#41;;
    return rec;
    

    }

    @



  • Hi,

    There are several points to make about the way you use Qt:

    • Qt Creator and Qt Designer use the same designer plugin. This means that Qt Creator doesn't have its own designer module for Qt Widgets, Qt Creator and Qt Designer just use a library, the same library. So you don't need to avoid Qt Creator. There is a catch though: If these QTango widgets provide a Qt Designer plugin so that you they are visible in Qt Designer's widget list, than it is important that the Qt Designer itself and QTango's designer plugin are compiled with the same toolchain and Qt version etc. If QTango is compiled with, say, Qt 4.8 than you need a Qt Creator compiled with Qt 4.8. The latest versions available from qt-project.org (and now from qt.io) are compiled with Qt5.
    • If you use Qt Creator, it is easy to use qmake in the IDE to build your projects. You can still use Qt Creator for your project even though you use Qt Designer fır UI design. Qt Creator makes it really easy to use Qt. qmake creates a native make/nmake/XCode/MSVC project file to compile project depending on the platform (it is called mkspec in qmake's parlance).
    • Even if you don't use Qt Creator, you can write a pro file for your project and use qmake. qmake is not part of Qt Creator but Qt itself.
    • Undefined reference errors are related to linked libraries. You need to link against at least QtCore and QtGui if your using Qt4. You should have QT += core gui in your pro file.

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.