Thanks for replying!
I started again from scratch carefully following the quickstart guide and got my code up and running again, however, I'm still not quite where I want to be. I ran into the following issues:
1) Every time I run CMake, the new build solution erases the files I've added to my project (it only keeps the .c and .h files that I've added with the NewModule and NewFilter utilities).
2) There are linker errors (LNK2001 unresolved external) that can only be resolved when I change the line "BCI2000_ADD_APPLICATION_MODULE()" in my CMakeList.txt file to "BCI2000_ADD_TOOLS_GUIAPP( )", compiling and then changing it back to "BCI2000_ADD_APPLICATION_MODULE()".
3)QImage from Qt gives me a runtime error saying it cannot find QImage (I've run my code in QT creator and against the latest build of the Qt library so I know it works). Every other Qt element works fine.
4) I was forced to re-write the autogenerated code in the main loop to something similar to what is used in main.cpp in the BCI2000Launcher module. I'm not using CoreModuleQT so I'm not quite sure if this has something to do with how QImage is called.
What I'm trying to do:
I'm trying to write an stand-alone application similar to BCI2000Viewer that can read BCI2000 files and perform some analysis on the signals off-line, in addition to some other fucntions that don't depend on the BCI2000 framework. In the future I plan to integrate it with SIGFRIED, however, as of now my main goal is to be able to read .dat files and perform analysis which will be visually available to the user in the GUI that I created in Qt designer. So far I've created a stand-alone GUI in QT creator and I'm trying to move my project to Microsoft Visual Studio 2010, so I can use the BCI2000 framework.
Thanks again for all your help!
Juan P.
Here is the code to my main function:
Code: Select all
#include <QtGui/QApplication>
#include "ExceptionCatcher.h"
#include "MainWindow.h"
#ifdef _WIN32
# include <Windows.h>
int main( int, char*[] );
int WINAPI
WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
return main( __argc, __argv );
}
#endif // _WIN32
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setOrganizationName( "WUSTL" );
a.setApplicationName( "ClinicalDAQ" );
MainWindow w;
w.show();
std::string message = "Aborting ";
message += a.applicationName().toLocal8Bit().constData();
FunctionCall< int() >
call( &QApplication::exec );
bool finished = ExceptionCatcher()
.SetMessage( message )
.Run( call );
return finished ? call.Result() : -1;
}
Here's the code to my MainWindow:
Code: Select all
#include "PCHIncludes.h"
#pragma hdrstop
#include "MainWindow.h"
#include "BCIError.h"
#include "ui_MainWindow.h"
#include "Marker.h"
#include "GraphicsScene.h"
#include <QtGui>
using namespace std;
const int IdRole = Qt::UserRole;
int Gsize;
int Gshp_inx;
QColor col;
int rbID;
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
Escene=new GraphicsScene(); //Sets up Scene to use in QGraphicsView
Escene->setSceneRect(QRect(0, 0, 661, 381));
VEscene=new QGraphicsScene(); //Sets up Scene to use in QGraphicsView
VEscene->setSceneRect(QRect(0, 0, 461, 301));
Sscene=new GraphicsScene(); //Sets up Scene to use in QGraphicsView
Sscene->setSceneRect(QRect(0, 0, 661, 381));
SCPscene=new GraphicsScene(); //Sets up Scene to use in QGraphicsView
SCPscene->setSceneRect(QRect(0, 0, 661, 381));
Eview = ui->ECSView; //Creates pointer to ECSView ui element
VEview =ui->VSECSView; //Creates pointer to ECSView ui element
Sview=ui->SigfriedView; //Creates pointer to SigfriedView ui element
SCPview=ui->SCPView; //Creates pointer to SigfriedView ui element
Eview->setScene(Escene);
Eview->setDragMode(QGraphicsView::RubberBandDrag); //Allows you to select multiple items click-dragging the cursor
Eview->setRenderHints(QPainter::Antialiasing); //Enable antialiasing
VEview->setScene(VEscene);
VEview->setRenderHints(QPainter::Antialiasing); //Enable antialiasing
Sview->setScene(Sscene);
Sview->setDragMode(QGraphicsView::RubberBandDrag); //Allows you to select multiple items click-dragging the cursor
Sview->setRenderHints(QPainter::Antialiasing); //Enable antialiasing
Sview->setScene(Sscene);
Sview->setDragMode(QGraphicsView::RubberBandDrag); //Allows you to select multiple items click-dragging the cursor
Sview->setRenderHints(QPainter::Antialiasing); //Enable antialiasing
FileNameRec1=""; //FileNameRec records the last valid image file path
FileNameRec2=""; //setting as blank at the start
FileNameRec3="";
//Read Default values
Gsize=ui->SizeSpinBox->value();
Gshp_inx=ui->ShapeMenu->currentIndex();
rbID=radioButtonSelected();
switch(rbID)
{
case 1:col=Qt::yellow;
break;
case 2:col=Qt::darkGreen;
break;
case 3:col=Qt::darkBlue;
break;
case 4:col=QColor(255,140,0,255);
break;
case 5:col=Qt::magenta;
break;
case 6:col=Qt::black;
break;
case 7:col=Qt::white;
break;
}
QObject::connect(Escene, SIGNAL(markerPos(qreal,qreal)), this, SLOT(on_addMarker(qreal,qreal)));
QObject::connect(Escene, SIGNAL(selectionChanged()), this, SLOT(on_selection()));
qApp->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete Escene;
delete Eview;
delete Sscene;
delete Sview;
delete ui;
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event) //using eventfilter to implement the Mousemove signal
{
if (event->type() == QEvent::MouseMove)
{
if (Eview->underMouse()==true) //restricting the operational area to Eview
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
Sceneposition=Eview->mapToScene(mouseEvent->pos());
ui->xdisplay2->setText(Cursorx.setNum(Sceneposition.x())); //displayed in x box
ui->ydisplay2->setText(Cursory.setNum(Sceneposition.y())); //displayed in y box
//the coordinates are with respect to the object the cursor is on.
}
else //display "N/A" when out of range
{
ui->xdisplay2->setText("N/A");
ui->ydisplay2->setText("N/A");
}
}
return false;
}
void MainWindow::on_ImageSelectButton1_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath()); //Open File Dialog
if (!fileName1.isEmpty()) //Check to see if a file is selected. If a file is selected pass image create QImage object
{
QImage image1(fileName1); //Load Image
if (image1.isNull()) //If not an image file display error
{
QMessageBox::information(this, tr("Sigfried Viewer"), tr("Cannot load %1.").arg(fileName1));
return;
}
FileNameRec1=fileName1; //storing the valid namepath for future reference
ui->ImageDirText1->setText(FileNameRec1);
QPixmap img1 = QPixmap::fromImage(image1);
Sscene->setBackgroundBrush(img1.scaled(661,381,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
Sview->setScene(Sscene);
Sview->setGeometry(QRect(310, 10, 661, 381));
Sview->show();
}
}
void MainWindow::on_ImageSelectButton2_clicked()
{
QString fileName2 = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath()); //Open File Dialog
if (!fileName2.isEmpty()) //Check to see if a file is selected. If a file is selected pass image create QImage object
{
QImage image2(fileName2); //Load Image
if (image2.isNull()) //If not an image file display error
{
QMessageBox::information(this, tr("ECS Viewer"), tr("Cannot load %1.").arg(fileName2));
return;
}
FileNameRec2=fileName2;
ui->ImageDirText2->setText(FileNameRec2);
QPixmap img2 = QPixmap::fromImage(image2);
Escene->setBackgroundBrush(img2.scaled(661,381,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
Eview->setScene(Escene);
Eview->setGeometry(QRect(310, 10, 661, 381));
Eview->show();
//VEscene->setBackgroundBrush(img2.scaled(461,301,Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation));
// VEview->setScene(VEscene);
//VEview->setGeometry(QRect(0, 0, 465, 305));
//VEview->show();
}
}
void MainWindow::on_ImageSelectButton3_clicked()
{
QString fileName3 = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath()); //Open File Dialog
if (!fileName3.isEmpty()) //Check to see if a file is selected. If a file is selected pass image create QImage object
{
QImage image3(fileName3); //Load Image
if (image3.isNull()) //If not an image file display error
{
QMessageBox::information(this, tr("SCP Viewer"), tr("Cannot load %1.").arg(fileName3));
return;
}
FileNameRec3=fileName3;
ui->ImageDirText3->setText(FileNameRec3);
QPixmap img3 = QPixmap::fromImage(image3);
SCPscene->setBackgroundBrush(img3.scaled(661,381,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
SCPview->setScene(SCPscene);
SCPview->setGeometry(QRect(310, 10, 661, 381));
SCPview->show();
}
}
void MainWindow::on_YellowMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(Qt::yellow);
}
Eview->update();
col=Qt::yellow;
}
void MainWindow::on_BlueMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(Qt::darkBlue);
}
Eview->update();
col=Qt::darkBlue;
}
void MainWindow::on_GreenMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(Qt::darkGreen);
}
Eview->update();
col=Qt::green;
}
void MainWindow::on_MagentaMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(Qt::magenta);
}
Eview->update();
col=Qt::magenta;
}
void MainWindow::on_OrangeMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(QColor(255,140,0,255));
}
Eview->update();
col=QColor(255,140,0,255);
}
void MainWindow::on_BlackMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(Qt::black);
}
Eview->update();
col=Qt::black;
}
void MainWindow::on_WhiteMarker_clicked()
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setOutlineColor(Qt::white);
}
Eview->update();
col=Qt::white;
}
void MainWindow::on_ShapeMenu_activated(int index)
{
Marker *marker;
Marker::Shape shape = Marker::Shape(index-1);//ui->ShapeMenu->itemData(
//ui->ShapeMenu->currentIndex(), IdRole).toInt());
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setShape(shape);
}
Eview->update();
Gshp_inx=ui->ShapeMenu->currentIndex();
}
void MainWindow::on_SizeSpinBox_valueChanged(int index)
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setSize(ui->SizeSpinBox->value());
}
Eview->update();
Gsize=ui->SizeSpinBox->value();
Gshp_inx=ui->ShapeMenu->currentIndex();
}
short MainWindow::getSize()
{
return Gsize;
}
QColor MainWindow::getColor()
{
return col;
}
int MainWindow::getShape()
{
return Gshp_inx;
}
int MainWindow::radioButtonSelected()
{
if(ui->YellowMarker->isChecked())
return 1;
else if(ui->GreenMarker->isChecked())
return 2;
else if(ui->BlueMarker->isChecked())
return 3;
else if(ui->OrangeMarker->isChecked())
return 4;
else if(ui->MagentaMarker->isChecked())
return 5;
else if(ui->BlackMarker->isChecked())
return 6;
else if(ui->WhiteMarker->isChecked())
return 7;
else
return 0;
}
void MainWindow::on_NoElectrodesSpinBox_valueChanged(int ElecValue)
{
ElecValue=ui->NoElectrodesSpinBox->value();
ui->ElectrodesTable->setRowCount(ElecValue);
}
void MainWindow::on_ImageDirText2_returnPressed()
{
QString fileName2 = ui->ImageDirText2->text();
if (!fileName2.isEmpty()) //Check to see if a file is selected. If a file is selected pass image create QImage object
{
QImage image2(fileName2); //Load Image
if (image2.isNull()) //If not an image file display error
{
QMessageBox::information(this, tr("ECS Viewer"), tr("Cannot load %1.").arg(fileName2));
ui->ImageDirText2->setText(FileNameRec2); //restoring to last valid filename
return;
}
FileNameRec2=fileName2; //storing for future reference
//view = new QGraphicsView(ui->ECSView); //Creates pointer to ECSView ui element
QPixmap img2 = QPixmap::fromImage(image2);
Escene->setBackgroundBrush(img2.scaled(661,381));
Eview->setScene(Escene);
Eview->setGeometry(QRect(310, 10, 661, 381));
Eview->show();
}
}
void MainWindow::on_ImageDirText1_returnPressed()
{
QString fileName1 = ui->ImageDirText1->text();
if (!fileName1.isEmpty()) //Check to see if a file is selected. If a file is selected pass image create QImage object
{
QImage image1(fileName1); //Load Image
if (image1.isNull()) //If not an image file display error
{
QMessageBox::information(this, tr("ECS Viewer"), tr("Cannot load %1.").arg(fileName1));
ui->ImageDirText1->setText(FileNameRec1); //restoring to the last valid name
return;
}
FileNameRec1=fileName1; //storing for future reference
//view = new QGraphicsView(ui->ECSView); //Creates pointer to ECSView ui element
QPixmap img1 = QPixmap::fromImage(image1);
Sscene->setBackgroundBrush(img1.scaled(661,381));
Sview->setScene(Sscene);
Sview->setGeometry(QRect(310, 10, 661, 381));
Sview->show();
}
}
void MainWindow::on_ImageDirText3_returnPressed()
{
QString fileName3 = ui->ImageDirText3->text();
if (!fileName3.isEmpty()) //Check to see if a file is selected. If a file is selected pass image create QImage object
{
QImage image3(fileName3); //Load Image
if (image3.isNull()) //If not an image file display error
{
QMessageBox::information(this, tr("ECS Viewer"), tr("Cannot load %1.").arg(fileName3));
ui->ImageDirText3->setText(FileNameRec3); //restoring to last valid filename
return;
}
FileNameRec2=fileName3; //storing for future reference
//view = new QGraphicsView(ui->ECSView); //Creates pointer to ECSView ui element
QPixmap img3 = QPixmap::fromImage(image3);
SCPscene->setBackgroundBrush(img3.scaled(661,381));
SCPview->setScene(SCPscene);
SCPview->setGeometry(QRect(310, 10, 661, 381));
SCPview->show();
}
}
void MainWindow::on_tabWidget_selected(const QString &arg1)
{
Marker *marker;
QList<QGraphicsItem *> items =Escene->items();
QListIterator<QGraphicsItem *> i(items);
while(i.hasNext())
{
marker=(Marker *)i.next();
marker->setSelected(false);
}
Eview->update();
QString fileName = "ECSview.png";
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
QPixmap pixMap = QPixmap::grabWidget(Eview);
VEscene->setBackgroundBrush(pixMap.scaled(461,301,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
}
void MainWindow::on_addMarker(qreal xpos1, qreal ypos1)
{
QString xval;
QString yval;
ui->xdisplay1->setText(xval.setNum(xpos1));
ui->ydisplay1->setText(yval.setNum(ypos1));
}
void MainWindow::on_selection()
{
QString xval;
QString yval;
Marker *marker;
QList<QGraphicsItem *> items =Escene->selectedItems();
QListIterator<QGraphicsItem *> i(items);
if (i.hasNext()==true && items.size()==1)
{
marker=(Marker *)i.next();
ui->xdisplay1->setText(xval.setNum(marker->getXpos()));
ui->ydisplay1->setText(yval.setNum(marker->getYpos()));
}
else
{
ui->xdisplay1->setText("");
ui->ydisplay1->setText("");
}
}
void MainWindow::on_SCPLoadDataButton_clicked()
{
}
MainWindow* MainWindow::self()
{
return this;
}