Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. connettere 2 form
Forum Update on Monday, May 27th 2025

connettere 2 form

Scheduled Pinned Locked Moved Unsolved Italian
2 Posts 2 Posters 579 Views
  • 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.
  • C Offline
    C Offline
    ceciacd79
    wrote on last edited by
    #1

    Vi spiego la situazione. Nel main principale ho un label nel quale vorrei scrivere la directory che ricavo da un Qtreeview di un secondo form. il problema è che non capisco come eseguire questa operazione.
    il label si chiama LB_source. alla pressione del pulsante PB_select_dir vorrei eseguire la connessione che mi copi la variabile pathdir nella LB_source.

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <frm_select.h>
    #include <ui_frm_select.h>
    #include <QTreeView>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        update_log("Start Application.");
    
        ui->tabWidget->setCurrentIndex(0);                                                      //  Set the stat tab page
    
    header label
        ui->tableWidget->horizontalHeader()->setStretchLastSection(true);                       //  Last colum auto maximize to conteiner
    
        qDebug()<<qApp->property("my_path");
    
        connect(newform,&QPushButton::clicked,ui->LB_source);
     }
    
    void MainWindow::update_log(QString commento)
    {
        QDateTime time = QDateTime::currentDateTime();
        QString printtime = time.toString("dd/MM/yy hh:mm:ss");
    
        ui->tableWidget->insertRow(ui->tableWidget->rowCount());
        ui->tableWidget->setItem(ui->tableWidget->rowCount()- 1, col_data, new QTableWidgetItem(printtime));
        ui->tableWidget->setItem(ui->tableWidget->rowCount()- 1, col_commento, new QTableWidgetItem(commento));
    
        ui->BA_source->setValue(0);
        ui->BA_destination->setValue(0);
    
        found_driver();
    }
    
    void MainWindow::found_driver()
    {
        qDebug()<< "Run: " << __FUNCTION__;
    
        QString testo="prova";
        ui->listWidget->addItem(testo);
    
        QDir directory;
        directory.setCurrent("C:/");
    
        if (directory.exists())
        {
            qDebug()<< "The directory exist.";
    
            int n = directory.count() ;
            qDebug()<< "file presenti: " << n - 2;
            qDebug()<< "Dimensione: " << directory.Size << "Byte";
    
            QStorageInfo storage(qApp->applicationDirPath());
                  if (storage.isValid() && storage.isReady()) {
                      qDebug() << "Name:" << storage.name();
                      qDebug() << "Display name:" << storage.displayName();
                      qDebug() << "Device:" << storage.device();
                      qDebug() << "Root path:" << storage.rootPath();
                      qDebug() << "File system type:" << storage.fileSystemType();
                      qDebug() << "Is valid?" << (storage.isValid() ? "yes" : "no");
                      qDebug() << "Is root?" << (storage.isRoot() ? "yes" : "no");
                      qDebug() << "Is ready?" << (storage.isReady() ? "yes" : "no");
                      qDebug() << "Is read only?" << (storage.isReadOnly() ? "yes" : "no");
                      qDebug() << "Bytes available:" << storage.bytesAvailable();
                      qDebug() << "Bytes free:" << storage.bytesFree();
                      qDebug() << "Bytes total:" << storage.bytesTotal() << endl;
                    }
    
            for (int i =0; i<n; i++)
            {
                QString nome = directory[i];
                if ((nome=='.') || ( nome ==".."))
                {
    
                }
                else
                {
                    qDebug()<< "indice " << i << ":" <<directory[i] << "dim:" << directory[i].size();
                }
            }
        }
        else
        {
            qDebug()<< "The directory no exist.";
        }
    
        QFileInfo file;
    
        if(QFileInfo("/Users/diego/Desktop/result.txt").exists())
        {
            //The file exists
            qDebug()<< "File log.txt found.";
        }
        else
            {
            //The file doesn't exist
            qDebug()<< "File log.txt not found";
        }
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_PB_analize_clicked(bool checked)
    {
        if (checked)
        {
            qDebug()<<"Press button analize";
            update_log("Select Analize operation.");
        }
    }
    
    void MainWindow::on_TB_sync_clicked(bool checked)
    {
        if (checked)
        {
            ui->TB_backup->setChecked(false);
            ui->TB_restore->setChecked(false);
        }
        update_log("Select Sync operation.");
    }
    
    void MainWindow::on_TB_backup_clicked(bool checked)
    {
        if (checked)
        {
            ui->TB_sync->setChecked(false);
            ui->TB_restore->setChecked(false);
        }
        update_log("Select BackUp operation.");
    }
    
    void MainWindow::on_TB_restore_clicked(bool checked)
    {
        if (checked)
        {
            ui->TB_backup->setChecked(false);
            ui->TB_sync->setChecked(false);
        }
        update_log("Select Restore operation.");
    }
    
    void MainWindow::on_PB_add_source_clicked()
    {
        newform = new frm_select(this);
        newform ->setModal(true);                   //  Open only this form
        newform ->show();
    }
    
    void MainWindow::on_actionItaliano_triggered()
    {
        ui->actionInglese->setChecked(false);
    }
    
    void MainWindow::on_actionInglese_triggered()
    {
        ui->actionItaliano->setChecked(false);
    }
    

    frm_select.cpp

    #include "frm_select.h"
    #include "ui_frm_select.h"
    #include <mainwindow.h>
    #include <QTreeView>
    
    frm_select::frm_select(QWidget *parent):
        QDialog(parent),
        ui(new Ui::frm_select)
    {
        ui->setupUi(this);
        qDebug()<<"Open select directory";
    
        dirmodel = new QDirModel(this);
        dirmodel->setReadOnly(false);                           //  Maker file system writable
        dirmodel->setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name);  // Set visualization tree
    
        ui->tree_source->setModel(dirmodel);
        QModelIndex index = dirmodel->index("C:/");
    
        ui->tree_source->expand(index);
        ui->tree_source->scrollTo(index);
        ui->tree_source->setCurrentIndex(index);
        ui->tree_source->resizeColumnToContents(0);             //  Resize the colum to contests
    }
    
    frm_select::~frm_select()
    {
        delete ui;
    }
    
    void frm_select::found_driver()
    {
         qDebug()<<"Run found_driver function.";
         QFileSystemModel *tree_source = new QFileSystemModel(this);
         tree_source->setRootPath(QDir::rootPath());
         ui->tree_source->setModel(tree_source);
         ui->tree_source->resizeColumnToContents(0);             //  Resize the colum to contests
    
         foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
             qDebug()<< storage.name();
             qDebug() << "Root path:" << storage.rootPath();
          //   ui->listWidget->addItem(storage.name());
         }
    }
    
    QString frm_select::on_PB_select_dir_clicked()
    {
        qDebug()<<"Press button select dir";
        ui->tree_source->resizeColumnToContents(0);             //  Resize the colum to contests
    
        QModelIndex index = ui->tree_source->currentIndex();
        if (!index.isValid()) return "";
    
        QString pathdir = dirmodel->filePath(index);
        qDebug()<< pathdir;
        return dirmodel->filePath(index);
    }
    
    void frm_select::on_PB_make_dir_clicked()
    {
        qDebug()<<"Press button make directory";
        QModelIndex index =ui->tree_source->currentIndex();
        if (!index.isValid()) return;
    
        QString newdir = QInputDialog::getText(this,"New directory name","Enter new directory");
        if (newdir.isEmpty()) return;
    
        dirmodel->mkdir(index,newdir);
    }
    
    void frm_select::on_PB_remove_clicked()
    {
        qDebug()<<"Press button remove";
        QModelIndex index =ui->tree_source->currentIndex();
    
        int reply = QMessageBox::question(this,tr("Confirm remove"), "Confirm remove?",QMessageBox::Yes,QMessageBox::No);
    
        if (reply==QMessageBox::Yes)
        {
            if (!index.isValid()) return;
    
            if (dirmodel->fileInfo(index).isDir())
            {
                dirmodel->rmdir(index);
            }
            else
            {
                dirmodel->remove(index);
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Il normale processo dei dialog modali e':

      1. il widget principale (MainWindow) crea il dialog
      2. dal widget principale chiami if(QDialog::exec())
      3. se l'if passa usa i metodi pubblici del dialog per estrarre i dati che ti servono

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      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