Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Calling one window from another

    General and Desktop
    3
    6
    1294
    Loading More Posts
    • 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
      kpks last edited by

      Hi,
      My application has multiple windows:
      1st window shows a log and allows user to select dynamic testing or viewing log data. This window works well so far.

      If dynamic testing is chosen, the window sets up a TcpSocket to listen for incoming data. This also works.

      But, at this point, I want the main window to call the Plot Window and hide itself. How do I do that?

      My workaround was to launch both the windows at the start of the application with the main window on top. But, once the data starts coming over the socket, I am unable to hide the main window.
      this->hide() is not working.
      hide is not working.

      An alternative could be, destroying/hiding two of the three widgets in the Mainwindow and replacing it with a groupbox and plot widget.
      I have used Qt Creator 2.8.1 to create the windows, I have NOT hand coded it.

      Thanks!

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        [quote author="kpks" date="1389857981"]
        My workaround was to launch both the windows at the start of the application with the main window on top. But, once the data starts coming over the socket, I am unable to hide the main window.
        this->hide() is not working.
        hide is not working.[/quote]
        Show some code please so we can tell you what you are doing wrong or what the issue is.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • dheerendra
          dheerendra Qt Champions 2022 last edited by

          showMinimized, showMaximized, show(), hide or setvisible(false) are the only options for you to manage this. As Raven said, better to give some clear code snippet. This helps us to give precise solution.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply Reply Quote 0
          • K
            kpks last edited by

            @#include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include "cprserver.h"
            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);
            //dPlot = new Ui::dynamicPlots;

            //connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
            

            }

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

            void MainWindow::on_quitButton_clicked()
            {
            close();
            }

            void MainWindow::on_pbFiles_clicked()
            {
            setUpListener();
            this->hide();

            }
            void MainWindow::setUpListener()
            {
            const QString IP = "127.0.0.1";
            const ushort port = 8100;
            QHostAddress host;

            host.setAddress(IP);
            if (!server.listen(host,port)) {
                QMessageBox::critical(this, tr("CPR Server"),
                                      tr("Unable to start the server: %1.")
                                      .arg(server.errorString()));
                close();
                //qDebug() <<  "Unable to start server" << server.errorString();
            
            }
            
            QString ipAddress=(server.serverAddress()).toString();
            qDebug () << "Server started at " << ipAddress ;//go to log
            //dPlot->show();
            
            //qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
            

            }

            void MainWindow::setPlotWindow(dynamicPlots* dp)
            {
            dPlot = dp;
            }@

            1 Reply Last reply Reply Quote 0
            • raven-worx
              raven-worx Moderators last edited by

              and where do you react to new connections?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply Reply Quote 0
              • K
                kpks last edited by

                That is in the listenandwrite thread:
                @#include "listenwritethread.h"

                #include <QtNetwork>

                listenWriteThread::listenWriteThread(int socketDescriptor, const QString &fortune, QObject *parent)
                : QThread(parent), socketDescriptor(socketDescriptor), text(fortune)
                {
                tcpSocket = new QTcpSocket;
                tcpSocket->setSocketDescriptor(socketDescriptor);

                }

                void listenWriteThread::run()
                {
                //qDebug()<<"Inside RUN!";
                /if (!tcpSocket->setSocketDescriptor(socketDescriptor)) {
                emit error(tcpSocket->error());
                return;
                }
                else qDebug()<<"Ready to Roll";
                /
                //qDebug()<<"Connection Up!";
                connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(analyzeThis()));
                }

                void listenWriteThread::analyzeThis()
                {
                //QTcpSOcket tcpSocket;
                //qDebug()<<"In Analyze!";
                QByteArray data = tcpSocket->readAll();
                QString sData=QString(data);
                QStringList dataList = sData.split(':');
                if ((dataList.size() >= 2) && dataList[0]=="Disp")
                {
                bool ok;
                int val = dataList[3].toInt(&ok,10);
                qDebug() << " Compression Depth " << val;
                }
                else
                qDebug() << "Data Error ! " << data;
                }@

                My next question is going to be how to connect thie data to the plot window for plotting. I am currently considering setting up a input vector and signalling everytime it gets 10 values full...
                There must be a more elegant solution though.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post