0

I have a mainWindow and a Dialog in Qt . I am opening two images in MainWindow . After I make operations with image (crop, resize, rotate ) on MainWindow . I want to send images to another window (QDialog) . How can i send it as a parameter? My partial code is below ;

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() function for open new Window

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

}

// new dialog window

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 );
}

// And here also my open() function

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();
         }

     }
 }

It looks good idea to use QGraphicsPixmapItem* item but i couldnt make it .. Could you help me? Thanks for ideas..

> EDİT: here also my open1 and open2 function to understand situation clearly..

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

void MainWindow::open2()
{
    open( 2 );
}
goGud
  • 4,163
  • 11
  • 39
  • 63
  • I can't figure out how you are sending signal to open function ? what is value of signal when open is called ? – Kunal Sep 05 '13 at 07:05
  • I am using two public slots : open1() and open2() thus i can send signal .. I dont call Open function with buttons . I am calling open() function in another function with values like open(1) or open(2) – goGud Sep 05 '13 at 07:13
  • `It looks good idea to use QGraphicsPixmapItem* item but i couldnt make it ` What do you mean by you couldn't make it? – thuga Sep 05 '13 at 07:14
  • @thuga I tried to use item object as a parameter for QDialog window but i couldnt make it. – goGud Sep 05 '13 at 07:16
  • @goGud Why? What happened? What exactly did you try? – thuga Sep 05 '13 at 07:17
  • @thuga I couldnt sent it as a parameter .. Actually i am new in qt i am trying to learn .. – goGud Sep 05 '13 at 07:23
  • @goGud Could you edit your question and show us how you tried to send it as a parameter, and show the function that receives it as a parameter? – thuga Sep 05 '13 at 07:30
  • You can also create QPixmap from filepath, no need to create QImage first and then create QPixmap from QImage and verify if you are getting valid QPixmap – Kunal Sep 05 '13 at 07:40

1 Answers1

1

The good way to do it will be using signals/slots
1. In main window declaration add smth like:

signals:
    void ImageProcessingDone(QImage& image);

2. In your dialog declare slot

public slosts:
     void RecevedProcessedImage(QImage& image);

3. Implpement slot for processing image.
4. In constructo of main window connect signal and slot.
So when your image processing will be done just write in MainWindow emit ImageProcessingDone(imageInstance) and it will be transfered to your dialog

Ruslan F.
  • 5,498
  • 3
  • 23
  • 42