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. Calling one window from another
Forum Updated to NodeBB v4.3 + New Features

Calling one window from another

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.5k 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
    kpks
    wrote on 16 Jan 2014, 07:39 last edited by
    #1

    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
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 16 Jan 2014, 07:45 last edited by
      #2

      [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
      0
      • D Offline
        D Offline
        dheerendra
        Qt Champions 2022
        wrote on 16 Jan 2014, 08:00 last edited by
        #3

        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
        0
        • K Offline
          K Offline
          kpks
          wrote on 16 Jan 2014, 08:05 last edited by
          #4

          @#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
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 16 Jan 2014, 08:10 last edited by
            #5

            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
            0
            • K Offline
              K Offline
              kpks
              wrote on 16 Jan 2014, 08:17 last edited by
              #6

              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
              0

              2/6

              16 Jan 2014, 07:45

              topic:navigator.unread, 4
              • Login

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