Running Qt C ++ code without QtCoreApplication / QCoreApplication under Linux (Ubuntu 13.10 and 14.04)

I have a strange error when I run my program under Linux. The message says: QApplication :: qAppName: Specify an instance of the QApplication object first. It works fine under Windows 8, but I want to submerge it in Linux without this dependency. Here is my code:

#include <QtCore/QCoreApplication>
#include <iostream>
#include <omd/opto.h>
#include <QThread>

int main(int argc, char *argv[])
{
//QCoreApplication a(argc, argv);

OptoPorts ports;
OPort* list=ports.listPorts(true);

std::cout<<"Available ports:"<<std::endl;
std::cout<<std::endl;
int i=0;
for (i=0;i<ports.getLastSize();i++)
    std::cout<<"   "<<i+1<<". "<<list[i].name<<" "<<list[i].deviceName<<std::endl;

std::cout<<ports.getLastSize();

std::cout<<std::endl;

if (i==0)
    {
    std::cout<<"No sensor found"<<std::endl;
    return -1;
    }

        int input;
        int timing;

        if (ports.getLastSize()==1)
            input=1;
        else
            std::cin>>input;

        OptoDAQ daq;
        daq.open(list[input-1]);


        while (true)
        {
        if (daq.getVersion()!=_95)
        {
                    OptoPackage* pa=0;

                    int size=daq.readAll(pa);

                    for (int i=0;i<size;i++)
                    {
                    std::cout<<"x: "<<pa[i].x<<" y: "<<pa[i].y<<" z: "<<pa[i].z<<" s1: "<<pa[i].s1<<" s2: "<<pa[i].s2<<" s3: "<<pa[i].s3<<" s4: "<<pa[i].s4<<" TEMP: "<<pa[i].temp<<std::endl;
                    }
        }
        else if (daq.getVersion()==_95)
        {
        OptoPackage6D* p6d=0;
        int size=daq.readAll6D(p6d,false);

        std::cout<<"SIZE:"<<size<<std::endl;
        for (int i=0;i<size;i++)
        {
            std::cout<<"Sensor1.x: "<<p6d[i].Sensor1.x<<" Sensor1.y: "<<p6d[i].Sensor1.y<<" Sensor1.z: "<<p6d[i].Sensor1.z<<" Sensor1.s1: "<<p6d[i].Sensor1.s1<<" Sensor1.s2: "<<p6d[i].Sensor1.s2<<" Sensor1.s3: "<<p6d[i].Sensor1.s3<<"  Sensor1.s4: "<<p6d[i].Sensor1.s4<<" TEMP: "<<p6d[i].Sensor1.temp<<std::endl;
            std::cout<<"Sensor2.x: "<<p6d[i].Sensor2.x<<" Sensor2.y: "<<p6d[i].Sensor2.y<<" Sensor2.z: "<<p6d[i].Sensor2.z<<" Sensor2.s1: "<<p6d[i].Sensor2.s1<<" Sensor2.s2: "<<p6d[i].Sensor2.s2<<" Sensor2.s3: "<<p6d[i].Sensor2.s3<<"  Sensor2.s4: "<<p6d[i].Sensor2.s4<<" TEMP: "<<p6d[i].Sensor2.temp<<std::endl;
            std::cout<<"Sensor3.x: "<<p6d[i].Sensor3.x<<" Sensor3.y: "<<p6d[i].Sensor3.y<<" Sensor3.z: "<<p6d[i].Sensor3.z<<" Sensor3.s1: "<<p6d[i].Sensor3.s1<<" Sensor3.s2: "<<p6d[i].Sensor3.s2<<" Sensor3.s3: "<<p6d[i].Sensor3.s3<<"  Sensor3.s4: "<<p6d[i].Sensor3.s4<<" TEMP: "<<p6d[i].Sensor3.temp<<std::endl;
            std::cout<<"Sensor4.x: "<<p6d[i].Sensor4.x<<" Sensor4.y: "<<p6d[i].Sensor4.y<<" Sensor4.z: "<<p6d[i].Sensor4.z<<" Sensor4.s1: "<<p6d[i].Sensor4.s1<<" Sensor4.s2: "<<p6d[i].Sensor4.s2<<" Sensor4.s3: "<<p6d[i].Sensor4.s3<<"  Sensor4.s4: "<<p6d[i].Sensor4.s4<<" TEMP: "<<p6d[i].Sensor4.temp<<std::endl;
        }
        }

        QThread::msleep(50);
        }

        daq.close();


//return a.exec();
return 0;

      

}

+3


source to share


1 answer


You don't need QCoreApplication if all you do is QThread :: msleep. I would suggest using the standard sleep library, but if you insist, it worked for me on both Windows 8.1 and Ubuntu 15.04 in Qt5.

main.cpp:

#include <QThread>

int main()
{
    QThread::sleep(5);
    return 0;
}

      



Used by CMake to set up on both ends without changing anything:

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.11)

find_package(Qt5Core REQUIRED)

add_executable(main main.cpp)
qt5_use_modules(main Core)

      

+1


source







All Articles