Calling one window from another



  • 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!


  • Moderators

    [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.



  • 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.



  • @#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;
    }@


  • Moderators

    and where do you react to new connections?



  • 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.


Log in to reply
 

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