我在Qt中有mainWindow
和Dialog
。我在MainWindow打开两张图片。在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
看起来不错,但我无法做到..你能帮助我吗?谢谢你的想法..
> EDİT:这里也是我的open1和open2函数,可以清楚地了解情况。
void MainWindow::open1()
{
open( 1 );
}
void MainWindow::open2()
{
open( 2 );
}
答案 0 :(得分:1)
这样做的好方法是使用信号/插槽
1.在主窗口声明中添加smth,如:
signals:
void ImageProcessingDone(QImage& image);
2。在你的对话框中声明插槽
public slosts:
void RecevedProcessedImage(QImage& image);
3。用于处理图像的Implpement槽。
4.在主窗口的构造中连接信号和插槽
因此,当您的图像处理完成后,只需在MainWindow中写入发出ImageProcessingDone(imageInstance),它就会被转移到您的对话框