How to get QDBusObjectPath in DBus? - qdbus

I have a problem in extracting the returned value from a method called on DBus,
here is my code:
QDBusPendingReply <QDBusObjectPath> reply = m_sysroot->GetOS(QStringLiteral("fedora"));
reply.waitForFinished();
if(! reply.isError()){
qWarning() << "No Error" << Qt::endl;
qWarning() << reply.argumentAt(0)<<Qt::endl;
}
else{
qWarning() <<"Error occurs" << Qt::endl;
}
here is the defination of GetOS:
<method name="GetOS">
<arg name="name" type="s"/>
<arg name="object_path" type="o" direction="out"/>
</method>
The output of the code is:
No Error
QVariant(QDBusObjectPath, )
How to get the object path ??
thanks

I have solved the problem by adding these 2 lines:
QDBusObjectPath objectPath = reply.argumentAt(0).value<QDBusObjectPath>();
qWarning() << objectPath.path() << Qt::endl;

Related

How can I tell whether a copy-node search failed, or whether my node or graph are invalid?

Consider the CUDA graphs API function cuFindNodeInClone(). The documentation says, that it:
Returns:
CUDA_SUCCESS, CUDA_ERROR_INVALID_VALUE
This seems problematic to me. How can I tell whether the search failed (e.g. because there is no copy of the passed node in the graph), or whether the node or graph are simply invalid (e.g. nullptr)? Does the second error value signify both? Can I get a third error value which is just not mentioned?
When using the runtime API, the returned node is nullptr if the original node does not exist in the cloned graph. For nullptr original node or nullptr cloned graph, the output node is left unmodified.
#include <iostream>
#include <cassert>
int main(){
cudaError_t status;
cudaGraph_t graph;
status = cudaGraphCreate(&graph, 0);
assert(status == cudaSuccess);
cudaGraphNode_t originalNode;
status = cudaGraphAddEmptyNode(&originalNode, graph, nullptr, 0);
assert(status == cudaSuccess);
cudaGraph_t graphclone;
status = cudaGraphClone(&graphclone, graph);
assert(status == cudaSuccess);
cudaGraphNode_t anotherNode;
status = cudaGraphAddEmptyNode(&anotherNode, graph, nullptr, 0);
assert(status == cudaSuccess);
cudaGraphNode_t nodeInClone = (cudaGraphNode_t)7;
status = cudaGraphNodeFindInClone(&nodeInClone, originalNode, graphclone);
std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";
nodeInClone = (cudaGraphNode_t)7;
status = cudaGraphNodeFindInClone(&nodeInClone, nullptr, graphclone);
std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";
nodeInClone = (cudaGraphNode_t)7;
status = cudaGraphNodeFindInClone(&nodeInClone, originalNode, nullptr);
std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";
nodeInClone = (cudaGraphNode_t)7;
status = cudaGraphNodeFindInClone(&nodeInClone, anotherNode, graphclone);
std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";
}
On my machine with CUDA 11.8, this prints
no error 0x555e3cf287c0
invalid argument 0x7
invalid argument 0x7
invalid argument 0

CGAL example cannot read input files?

this is my first stackoverflow question, so I hope the following text meets the question requirements. If not, please tell me what needs to be changed so I can adapt the question.
I'm new to CGAL and C++ in general. I would like to use CGAL 5.0.2 on a Macbook Pro early 2015 with macOS Catalina Version 10.15.4.
So to begin with, I followed the instruction steps given by the CGAL documentation using the package manager Homebrew. Since CGAL is a header-only library I configured it using CMake, as is recommended by the documentation.
It all worked out fine, so I went on trying the recommended examples given in the file CGAL-5.0.2.tar.xz, which is provided here. I'm particularly interested in the example Voronoi_Diagram_2.
Using the Terminal I executed the command -DCGAL_DIR=$HOME/CGAL-5.0.2 -DCMAKE_BUILD_TYPE=Release . in the example folder called Voronoi_Diagram_2. Then I executed the command make. All went well, no error messages were prompted. But executing the resulting exec file didn't produce any results.
After some research I managed to modify the code in a way that it prints the values of some variables. Problem seems to be that the input file which contains the line segments for which the voronoi diagramm shall be calculated is not correctly read.
The while loop which I highlighted in the code below by inserting //// signs seems not to be entered. That's why I assume that the variable ifs is empty, even though the input file "data1.svd.cin", which can be found in the folder "data" of the example, wasn't.
Does anyone have an idea for the reasons of this behaviour? Any help is appreciated.
This is the vd_2_point_location_sdg_linf.cpp file included in the example, which I modified:
// standard includes
#include <iostream>
#include <fstream>
#include <cassert>
// includes for defining the Voronoi diagram adaptor
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Segment_Delaunay_graph_Linf_filtered_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_Linf_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_2.h>
// typedefs for defining the adaptor
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Segment_Delaunay_graph_Linf_filtered_traits_2<K> Gt;
typedef CGAL::Segment_Delaunay_graph_Linf_2<Gt> DT;
typedef CGAL::Segment_Delaunay_graph_adaptation_traits_2<DT> AT;
typedef CGAL::Segment_Delaunay_graph_degeneracy_removal_policy_2<DT> AP;
typedef CGAL::Voronoi_diagram_2<DT,AT,AP> VD;
// typedef for the result type of the point location
typedef AT::Site_2 Site_2;
typedef AT::Point_2 Point_2;
typedef VD::Locate_result Locate_result;
typedef VD::Vertex_handle Vertex_handle;
typedef VD::Face_handle Face_handle;
typedef VD::Halfedge_handle Halfedge_handle;
typedef VD::Ccb_halfedge_circulator Ccb_halfedge_circulator;
void print_endpoint(Halfedge_handle e, bool is_src) {
std::cout << "\t";
if ( is_src ) {
if ( e->has_source() ) std::cout << e->source()->point() << std::endl;
else std::cout << "point at infinity" << std::endl;
} else {
if ( e->has_target() ) std::cout << e->target()->point() << std::endl;
else std::cout << "point at infinity" << std::endl;
}
}
int main()
{
std::ifstream ifs("data/data1.svd.cin");
assert( ifs );
VD vd;
Site_2 t;
// /////////// Inserted Comment ////////////////////////////////
std::cout << "In the following the insertion from ifs should take place" << std::flush;
// ///////////////// while loop which doesn't seem to be active //////////////////
while ( ifs >> t ) {
// Existing Code to insert the points in the voronoi structure
vd.insert(t);
// Inserted Code to check if while loop is entered
std::cout << "Entered while loop" << std::flush;
}
// ///////////////////////////////////////////////////////////////////////////////
ifs.close();
assert( vd.is_valid() );
std::ifstream ifq("data/queries1.svd.cin");
assert( ifq );
Point_2 p;
while ( ifq >> p ) {
std::cout << "Query point (" << p.x() << "," << p.y()
<< ") lies on a Voronoi " << std::flush;
Locate_result lr = vd.locate(p);
if ( Vertex_handle* v = boost::get<Vertex_handle>(&lr) ) {
std::cout << "vertex." << std::endl;
std::cout << "The Voronoi vertex is:" << std::endl;
std::cout << "\t" << (*v)->point() << std::endl;
} else if ( Halfedge_handle* e = boost::get<Halfedge_handle>(&lr) ) {
std::cout << "edge." << std::endl;
std::cout << "The source and target vertices "
<< "of the Voronoi edge are:" << std::endl;
print_endpoint(*e, true);
print_endpoint(*e, false);
} else if ( Face_handle* f = boost::get<Face_handle>(&lr) ) {
std::cout << "face." << std::endl;
std::cout << "The vertices of the Voronoi face are"
<< " (in counterclockwise order):" << std::endl;
Ccb_halfedge_circulator ec_start = (*f)->ccb();
Ccb_halfedge_circulator ec = ec_start;
do {
print_endpoint(ec, false);
} while ( ++ec != ec_start );
}
std::cout << std::endl;
}
ifq.close();
return 0;
}

QT Sql Error: Not positioned on a valid record

I am unable to run Select query using QODBC (don't need QMysql). They throw QSqlQuery::value: not positioned on a valid record. However, other queries run fine.
There are other threads on the same issue on Stackoverflow. But none of them solves my problem. Here are a few
QSqlQuery not positioned on a valid record
Select query returns "value: not positioned on a valid record" in Qt
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={MySQL ODBC 8.0 UNICODE Driver};DATABASE=dbname;");
db.setUserName("root");
db.setPassword("mysql");
if (!db.open()) {
qDebug() << db.lastError();
} else {
QSqlQuery query;
query.prepare("SELECT id, name FROM users where id=1;");
if (!query.exec())
{
qDebug() << "SQL error: "<< query.lastError().text() << endl;
}
query.first();
qDebug() << query.value("name").toString() ;
}
Help appreciated

How to output the concrete contents of a QsqlQuery before execution

For debuging prurpose I wouls like to print a sql query I am executing.
Here is my code:
QSqlQuery query;
query.prepare("INSERT INTO GeoAndEnergies VALUES(:smi,:chismi,:index,:rank,:comp,:met,:ba,:nha, :na, :gr, :gconv, :scfconv, :ener,:chemf,:prog,:ver,:cha,:mult,:sol,:geo, :freq, :enth, :free_e, :wei)");;
query.bindValue(":smi",QVariant(SMILES));
query.bindValue(":chismi",QVariant(ChiralSMILES));
query.bindValue(":index",QVariant(IndexCS));
query.bindValue(":rank",QVariant(Confrank));
query.bindValue(":comp",QVariant(Comptype));
query.bindValue(":met",QVariant(Method));
query.bindValue(":ba",QVariant(BASE));
query.bindValue(":nha",QVariant(NheavyAtom));
query.bindValue(":na",QVariant(NAtoms));
query.bindValue(":gr",QVariant(Grid));
query.bindValue(":gconv",QVariant(GeoConvergence));
query.bindValue(":scfconv",QVariant(SCFConvergence));
query.bindValue(":ener",QVariant(Energy));
query.bindValue(":chemf",QVariant(ChemicalFormula));
query.bindValue(":prog",QVariant(SOFTWARE));
query.bindValue(":ver",QVariant(VERSION));
query.bindValue(":cha",QVariant(Charge));
query.bindValue(":mult",QVariant(Multiplicity));
query.bindValue(":sol",QVariant(SOLVANT));
query.bindValue(":geo",QVariant(Geometry));
query.bindValue(":freq",QVariant(freq));
query.bindValue(":enth",QVariant(enthalpy));
query.bindValue(":free_e",QVariant(free_enthalpy));
query.bindValue(":wei",QVariant(weight));
if (!query.exec()){
std::cout << "Une erreur s'est produite. :(" << std::endl << q2c(query.lastError().text()) << std::endl;
}
return;
Thanks for tips.
query.executedQuery() will return the text of the last query that was successfully executed, with placeholder values replaced with concrete values. Hopefully, it'll also work if there was an error due to bad values, etc.
Note also that the explicit QVariant constructions are never necessary. For types that are handled by QVariant, the conversion will be done automatically. For custom types, there's no QVariant constructor available and the code won't compile anyway. You'd need to use QVariant::fromValue(xyz), where xyz has a custom type that has been Q_DECL_METATYPE'd in the header where the type is declared.
Your code could be rewritten as follows:
QSqlQuery query;
query.prepare("INSERT INTO GeoAndEnergies VALUES(:smi,:chismi,:index,:rank,:comp,:met,:ba,:nha, :na, :gr, :gconv, :scfconv,"
":ener,:chemf,:prog,:ver,:cha,:mult,:sol,:geo, :freq, :enth, :free_e, :wei)");
query.bindValue(":smi", SMILES);
query.bindValue(":chismi", ChiralSMILES);
query.bindValue(":index", IndexCS);
query.bindValue(":rank", Confrank);
query.bindValue(":comp", Comptype);
query.bindValue(":met", Method);
query.bindValue(":ba", BASE);
query.bindValue(":nha", NheavyAtom);
query.bindValue(":na", NAtoms);
query.bindValue(":gr", Grid);
query.bindValue(":gconv", GeoConvergence);
query.bindValue(":scfconv", SCFConvergence);
query.bindValue(":ener", Energy);
query.bindValue(":chemf", ChemicalFormula);
query.bindValue(":prog", SOFTWARE);
query.bindValue(":ver", VERSION);
query.bindValue(":cha", Charge);
query.bindValue(":mult", Multiplicity);
query.bindValue(":sol", SOLVANT);
query.bindValue(":geo", Geometry);
query.bindValue(":freq", freq);
query.bindValue(":enth", enthalpy);
query.bindValue(":free_e", free_enthalpy);
query.bindValue(":wei", weight);
if (!query.exec()) {
qWarning() << "The query has failed:" << query.executedQuery();
}

IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unresolved

I am working on a assignment for school and I am having some issues i havnet been able to figure out
I got 2 files Stundet.cpp and Student.h
in my Student.h i am declaring a Student class
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
class Student
{private:
string fname;
string lname;
int ID;
public:
Student();
Student(string first,string last, int ID_num);
static int numberOfStudents;
void getName();
void getID();
};
in my Student.cpp i got
`#include <iostream>
#include "Student.h"
#include <string>
using namespace std;
Student::Student()
{numberOfStudents+=1;
}
Student::Student(string first, string last, int ID_num)
{fname=first;
lname=last;
ID=ID_num;
numberOfStudents+=1;}
int Student::numberOfStudents=0;
void Student::getName()
{cout<<fname<<lname;}
void Student::getID()
{cout<<ID;}
main()
{
Student st1("Hakan", "Haberdar", 1234), st2("Charu", "Hans", 2345), st3("Tarikul", "Islam", 5442), st4;
cout << "We created " << Student::numberOfStudents << " student objects." << endl;
cout << st1.getID() << " " << st1.getName() << endl;
cout << st2.getID() << " " << st2.getName() << endl;
cout << st3.getID() << " " << st3.getName() << endl;
cout << st4.getID() << " " << st4.getName() << endl;
system("pause");
} `
my first issue is that i keep getting these external errors that i have no idea how to fix, ive looked around but i dont really understand how to apply what i find. My errors are
Error 1 error LNK2001: unresolved external symbol _WinMainCRTStartup C:\Users\Tato- laptop\Documents\Visual Studio 2010\Projects\Student Class\Student Class\LINK
and
Error 2 error LNK1120: 1 unresolved externals C:\Users\Tato- laptop\Documents\Visual Studio 2010\Projects\Student Class\Debug\Student Class.exe 1
My second issues is that the couts in the .cpp file stopped working, i understand im supposed to overload them or something but I dont really understand how
Any help would be appreciated.