Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why my addText() function dont work?



  • Why my addText() function dont work?
    Here is code

    /* Dialog Example */
    #include "mainwindow.h"
    #include <QApplication>
    #include <QGridLayout>
    #include <QLabel>
    #include <QLineEdit>
    #include <QMainWindow>
    #include <QPushButton>
    #include <QTextBrowser>
    #include <QWidget>
    class GUI : public QMainWindow {
    
           Q_OBJECT
    
           QWidget *window;
           QLineEdit *gui001;
           QTextBrowser *gui002;
           QTextBrowser *gui003;
           QTextBrowser *gui004;
           QTextBrowser *gui005;
           QTextBrowser *gui006;
           QTextBrowser *gui007;
           QTextBrowser *gui008;
           QTextBrowser *gui009;
           QTextBrowser *gui010;
           QTextBrowser *gui011;
           QPushButton *forward;
    
         public:
           GUI();
           virtual ~GUI();
           void addText();
    
         private:
    };
    
    GUI::GUI() {
           window = new QWidget();
           QGridLayout *layout = new QGridLayout;
    
           // Sukuriami procesų label'iai
    
           QLabel *startStopLabel = new QLabel( "Start_Stop" );
           QLabel *readUILabel = new QLabel( "ReadUI" );
           QLabel *jclLabel = new QLabel( "JCL" );
           QLabel *dataToOutputLabel = new QLabel( "DataToOutput" );
           QLabel *inputToRamLabel = new QLabel( "InputToRam" );
           QLabel *mainProcLabel = new QLabel( "MainProc" );
           QLabel *jobGovernorLabel = new QLabel( "JobGovernor" );
           QLabel *loaderLabel = new QLabel( "Loader" );
           QLabel *virtualMachineLabel = new QLabel( "VirtualMachine" );
           QLabel *interruptLabel = new QLabel( "Interrupt" );
           QLabel *printErrorLabel = new QLabel( "PrintError" );
    
           // Sukuriami procesų laukai duomenų išvedimui
    
           gui001 = new QLineEdit();
           QString qString01 = "GUI-001  QLineEdit 01";
           gui001->setText( qString01 );
           gui002 = new QTextBrowser();
           qString01 = "GUI-002  QTextBrowser 02";
           gui002->setText( qString01 );
           gui003 = new QTextBrowser();
           qString01 = "GUI-003  QTextBrowser 03";
           gui003->setText( qString01 );
           gui004 = new QTextBrowser();
           qString01 = "GUI-004  QTextBrowser 04";
           gui004->setText( qString01 );
    
           gui005 = new QTextBrowser();
           qString01 = "GUI-005  QTextBrowser 05";
           gui005->setText( qString01 );
           gui006 = new QTextBrowser();
           qString01 = "GUI-006  QTextBrowser 06";
           gui006->setText( qString01 );
           gui007 = new QTextBrowser();
           qString01 = "GUI-007  QTextBrowser 07";
           gui007->setText( qString01 );
           gui008 = new QTextBrowser();
           qString01 = "GUI-008  QTextBrowser 08";
           gui008->setText( qString01 );
           gui009 = new QTextBrowser();
           qString01 = "GUI-009  QTextBrowser 09";
           gui009->setText( qString01 );
           gui010 = new QTextBrowser();
           qString01 = "GUI-010  QTextBrowser 10";
           gui010->setText( qString01 );
           gui011 = new QTextBrowser();
           qString01 = "GUI-011  QTextBrowser 11";
           gui011->setText( qString01 );
           forward = new QPushButton( "Forward" );
           connect( forward, SIGNAL( clicked() ), this, SLOT( addText() ) );
    
           layout->addWidget( startStopLabel, 0, 0, Qt::AlignHCenter );
           layout->addWidget( readUILabel, 0, 1, Qt::AlignHCenter );
           layout->addWidget( jclLabel, 0, 2, Qt::AlignHCenter );
           layout->addWidget( dataToOutputLabel, 0, 3, Qt::AlignHCenter );
           layout->addWidget( gui001, 1, 0 );
           layout->addWidget( gui002, 1, 1 );
           layout->addWidget( gui003, 1, 2 );
           layout->addWidget( gui004, 1, 3 );
           layout->addWidget( inputToRamLabel, 2, 0, Qt::AlignHCenter );
           layout->addWidget( mainProcLabel, 2, 1, Qt::AlignHCenter );
           layout->addWidget( jobGovernorLabel, 2, 2, Qt::AlignHCenter );
           layout->addWidget( loaderLabel, 2, 3, Qt::AlignHCenter );
           layout->addWidget( gui005, 3, 0 );
           layout->addWidget( gui006, 3, 1 );
           layout->addWidget( gui007, 3, 2 );
           layout->addWidget( gui008, 3, 3 );
           layout->addWidget( virtualMachineLabel, 4, 0, Qt::AlignHCenter );
           layout->addWidget( interruptLabel, 4, 1, Qt::AlignHCenter );
           layout->addWidget( printErrorLabel, 4, 2, Qt::AlignHCenter );
           layout->addWidget( gui009, 5, 0 );
           layout->addWidget( gui010, 5, 1 );
           layout->addWidget( gui011, 5, 2 );
           layout->addWidget( forward, 5, 3 );
    
           window->setLayout( layout );
           window->setWindowState( Qt::WindowMaximized );
           window->setWindowTitle( "AutoMagic" );
           window->setWindowIcon( QIcon( "kiriya.jpg" ) );
           window->show();
    }
    
    GUI::~GUI() {}
    
    void GUI::addText() {
           QString qString01 = "works";
           gui001->setText( qString01 );
           window->repaint();
    }
    
    int main( int argc, char *argv[] ) {
           QApplication app( argc, argv );
           GUI dialog;
           return app.exec();
    }
    
    #include "main.moc"
    
    

  • Lifetime Qt Champion

    @ElfMoon addText was not declared as slot. It needs to be:

    public slots:
        void addText();
    

    Please read https://doc.qt.io/qt-5/signalsandslots.html


Log in to reply