0

Qt にamainWindowと aがあります。DialogMainWindow で 2 つの画像を開いています。MainWindow で画像(クロップ、サイズ変更、回転)を操作した後。他の に画像を送信したいwindow (QDialog)。として送信するにはどうすればよいparameterですか?私の部分的なコードは以下です。

MainWindow::MainWindow()
{
   openButton_1 = new QPushButton(tr("Open"));
   cropButton_1 = new QPushButton(tr("Crop"));
   rotateButton_1 = new QPushButton(tr("Rotate"));
   resizeButton_1 = new QPushButton(tr("Resize"));
   doneButton = new QPushButton(tr("Done"));

   ....
   ....
   ....
   ....
   ....


   connect(openButton_1, SIGNAL(clicked()), this, SLOT(open1()));
   connect(openButton_2, SIGNAL(clicked()), this, SLOT(open2()));

   connect(doneButton, SIGNAL(clicked()), this, SLOT(done()));

// 新しいウィンドウを開く done() 関数

void MainWindow::done()
{
    CompareImage dialog(this);
    dialog.exec();

}

// 新しいダイアログ ウィンドウ

CompareImage::CompareImage( QWidget *parent ) : QDialog( parent )
{
   pushButton = new QPushButton(tr("TesT"));

   graphicsScene = new QGraphicsScene;
   graphicsView = new QGraphicsView(graphicsScene);



   QVBoxLayout *mainLayout = new QVBoxLayout;
   mainLayout->addWidget( pushButton );
   mainLayout->addWidget( graphicsView );
   setLayout( mainLayout );
}

// そして、ここでも私の open() 関数

void MainWindow::open( int signal )
 {
     QString fileName = QFileDialog::getOpenFileName(this,
                                     tr("Open File"), QDir::currentPath());
     if (!fileName.isEmpty()) {
         QImage image(fileName);
         if (image.isNull()) {
             QMessageBox::information(this, tr("Image Viewer"),
                                      tr("Cannot load %1.").arg(fileName));
             return;
         }
         QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(image));

         if( signal == 1 )
         {
             graphicsScene_1->addItem(item);
             graphicsView_1->show();
         }
         else if(signal == 2)
         {
             graphicsScene_2->addItem(item);
             graphicsView_2->show();
         }

     }
 }

使用するのは良い考えに見えますQGraphicsPixmapItem* item が、私はそれを作ることができませんでした..私を助けてもらえますか? アイデアをありがとう..

>編集:ここでも、状況を明確に理解するための私のopen1およびopen2関数..

void MainWindow::open1()
{
    open( 1 );
}

void MainWindow::open2()
{
    open( 2 );
}
4

1 に答える 1

1

これを行う良い方法は、シグナル/スロット
1 を使用することです。メイン ウィンドウの宣言で、次のようなものを追加します。

signals:
    void ImageProcessingDone(QImage& image);

2. ダイアログでスロットを宣言します

public slosts:
     void RecevedProcessedImage(QImage& image);

3. 画像処理用の実装スロット。
4. メイン ウィンドウの構成で、信号とスロットを接続します。
したがって、画像処理が完了したら、MainWindow に書き込むだけで ImageProcessingDone(imageInstance) を発行し、ダイアログに転送されます。

于 2013-09-05T08:04:09.353 に答える