Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] calling a function outside of the dialog class
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] calling a function outside of the dialog class

Scheduled Pinned Locked Moved General and Desktop
20 Posts 3 Posters 7.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #11

    is the above code suppose to go to the clicked function as soon as the dialog window is closed? because its not working.

    i have void clicked(); in the mainwindow.h

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #12

      I'm assuming it's supposed to be called when you click the login button on the dialog. That's what I read from your code you posted.

      Without a better synopsis of what you're trying to accomplish, it's very hard to figure out. There's a number of threads which are going simultaneously covering a number of issues.

      I think that perhaps there's a fundamental flaw in the design and logic of what's going on in the app, so it makes it kind of a hard moving target.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #13

        yes, its supposed to be called when the user clicks the login button on the dialog. i have verified that the clicked function never gets called.

        here is the mainwindow.cpp
        @#include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include "loginbox.h"
        #include <QRegExp>
        #include <QSettings>
        //#include <QTcpSocket>

        QString serverLineEdit;
        QString userLineEdit;
        int connect1 = 0;

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        login = new loginBox(this);

        login->setModal(true);
        

        login->show();
        connect(login, SIGNAL(click()), this, SLOT(clicked()));

        }

        void MainWindow::clicked(){
        QSettings settings("config.ini", QSettings::IniFormat);
        serverLineEdit = settings.value("serverLineEdit").toString();
        userLineEdit = settings.value("userLineEdit").toString();
        connect1 = settings.value("ConnectToServer").toInt();
        socket = new QTcpSocket(this);

            this->connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
            this->connect(socket, SIGNAL(connected()), this, SLOT(connected()));
        
            socket->connectToHost(serverLineEdit, 4200);
        

        }
        @

        and the dialog.cpp
        @#include "loginbox.h"
        #include "ui_loginbox.h"
        #include "mainwindow.h"
        #include <QRegExp>
        #include <QSettings>
        int connect2;

        loginBox::loginBox(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::loginBox)
        {
        ui->setupUi(this);
        }

        loginBox::~loginBox()
        {
        delete ui;
        }

        void loginBox::on_loginButton_clicked()
        {
        connect2 = 1;
        //save the result of serverLineEdit to the config.ini file
        QSettings settings("config.ini", QSettings::IniFormat);
        settings.setValue("serverLineEdit", ui->serverLineEdit->text());
        settings.setValue("userLineEdit", ui->userLineEdit->text());
        settings.setValue("ConnectToServer", connect2);
        this->close();

        }@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #14

          Overall design issues notwithstanding...

          Make the connect immediately after the "new loginBox(this)". (Move it from line 22 to line 19 above)

          But much more importantly, you also have to actually emit your click() signal in the dialog box. That needs to happen between lines 27 and 28 in dialog.cpp above.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kalster
            wrote on last edited by
            #15

            can i have an example on how to emit the click() signal in the dialog.cpp file?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #16

              @
              emit click();
              @

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #17

                If you're not intimately familiar with signals and slots, I highly recommend reading "this":http://doc.qt.nokia.com/4.7-snapshot/signalsandslots.html overview. Please. :)

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #18

                  thanks a bunch mlong. the code works great now :)
                  yes, i will read signals and slots

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mlong
                    wrote on last edited by
                    #19

                    Glad it's working!

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kalster
                      wrote on last edited by
                      #20

                      also, i am starting to understand what can and can't be done inside of a constructor.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved