I want to have the output of qconf redirected to test_settings.txt in my tmp folder. I've thought of two possibilities:
QProcess procWriteProject;
procWriteProject.start("qconf", QStringList() << " -sprj "
<< projectList[0] << " >> " << "\"/tmp/testing.txt\"");
procWriteProject.start("qconf -sprj " + projectList[0] + " >> "
+ "/tmp/test_settings");
Will either of those work? Is there a better way?
QProcess procWriteProject;
procWriteProject.setStandardOutputFile("/tmp/test_settings.txt");
procWriteProject.start("qconf", QStringList() << "-sprj" << projectList[0]);
Related
I am on a Windows Server which is in the same network as the Server with the computer name service.
I got this simple code which tries to list the content
QFileInfoList fiList = QDir("\\service\\Documents").entryInfoList(QDir::Files);
qDebug() << "sizeof filist: " << fiList.size();
for (const QFileInfo& fi : fiList)
{
qDebug() << fi.absoluteFilePath();
}
The output is the following:
sizeof filist: 0
I make sure that the folder is shared on the network by checking the properties and also using the windows explorer. I can access the folder via Windows Explorer.
Is the functionality I am trying to achieve not possible with QDir?
It turns out there are 2 backslashes more needed because \ needs to be escaped.
So the right code would be:
QFileInfoList fiList = QDir("\\\\service\\Documents").entryInfoList(QDir::Files);
qDebug() << "sizeof filist: " << fiList.size();
for (const QFileInfo& fi : fiList)
{
qDebug() << fi.absoluteFilePath();
}
I used Qt on MAC OS and try to retrieve the metadata of media. So i took the Qt's Media Player Example (Qt 5.8.0) and modified a little bit:
Instead of:
connect(controls, SIGNAL(play()), player, SLOT(play()));
i used:
connect(controls, &PlayerControls::play, player,
[this]{
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Size);
player->play();
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Resolution);
});
The results are:
false
QVariant(Invalid)
false
QVariant(Invalid)
1st question: why is the metadata not available even after the media started playing?
2nd question: i added some codes in the destructor:
Player::~Player()
{
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Duration);
}
Now the metadata is available, but no data is returned:
true
QVariant(Invalid)
Can anyone help me please?
Update Question 1:
Instead of
connect(controls, SIGNAL(pause()), player, SLOT(pause()));
i used:
connect(controls, &PlayerControls::pause, player,
[this]{
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Resolution);
});
And after about 3-5 seconds of playing, the metadata is already available, but it also returns nothing:
true
QVariant(Invalid)
This is not the exact answer for your question but this may help you. You can check which metadata available with this code:
QMetaDataReaderControl *c = qobject_cast<QMetaDataReaderControl*>(player_->service()->requestControl(QMetaDataReaderControl_iid));
if(c) {
connect(c, &QMetaDataReaderControl::metaDataAvailableChanged, [c](bool) {
qDebug() << c->availableMetaData();
});
}
I', not sure, but I think that qDebug cannot handle QVariant, you should use for example:
qDebug() << (player->metaData(QMediaMetaData::Title)).toString();
I have some issue in passing a FTP string into QUrl:
std::cout << QUrl::fromUserInput("ftp://user#host.com:password#ftphost:21/path/file.ext").toString().toStdString().c_str() << std::endl;
Is always resulting in
http://ftp//user#host.com:password#ftphost:21/path/file.ext
which is obviously wrong. What's the problem with the above FTP Url? Or is that a known issue within Qt4?
I am working on Linux, using Qt 4.8.1.
Even following code
if(QUrl("ftp://user#host.com:password#ftphost:21/path/file.ext").isValid())
std::cout << "is valid" << std::endl;
else
std::cout << "is not valid" << std::endl;
Is resulting in "is not valid"
Thanks in advance
You need manually replace # in username with %40. That's what QUrl does internally if QUrl::setUserName() is called with user#domain.tld.
I am building a telnet server app in Qt, and when I connect from a linux telnet client output looks great. For example, sending "A" << endl << "B" << endl << "C" to my console looks like:
A
B
C
Now when I connect from a Windows telnet client I see
A
B
C
obviously Qt's endl is sending only '\n'. Is there a SIMPLE solution to this? If I replace endl with "\r\n" do I mess up linux clients now? Do I have to force a flush too?
Here is actual code I am using to send to my telnet client:
QString block;
QTextStream out(&block, QIODevice::WriteOnly);
out << "Valid commands are: " << endl
<< " help Print this list" << endl
<< " version Print this version" << endl
<< " clientcount Show the number of active telnet clients" << endl
<< " logrotate Rotate the event log file" << endl
<< " shutdown Initiate shutdown secast" << endl
<< " quit Disconnect your telnet session" << endl
<< " stop Shutdown secast" << endl;
tcpSocketPtr->write(block.toUtf8());
You could simply drop the QTextStream and write the QString directly in here:
QString block = QString("Valid commands are: \n")
+ " help Print this list\n"
+ " version Print this version\n"
+ " clientcount Show the number of active telnet clients\n"
+ " logrotate Rotate the event log file\n"
+ " shutdown Initiate shutdown secast\n"
+ " quit Disconnect your telnet session\n"
+ " stop Shutdown secast\n";
tcpSocketPtr->write(block.toUtf8());
Based on your comment though, you seem to use some old DOS client (on Windows!) which expects "\r\n". In that case, I would send "\r\n" for that, but only the usual "\n" for Linux. It is a not so good practice to send carriage return as well on Linux, and not just line feed even though "\r\n" may seem to work on Linux.
How can I print the address typed by the user? This way don't work.
This is the code. Thanks.
#include <iostream>
using namespace std;
int main()
{
int num = 123456;
int *addr = #
cout << "Var: num, address: " << &num << ", has: " << num << endl
<< "Var: *addr, address: " << &addr << ", has: " << addr << endl
<< "Printing value of num using the pointer *addr: " << *addr << endl;
int addr_user;
cout << "Type the memory address: "; cin >> addr_user;
int *p_addr_user = (int *)addr_user;
cout << "The address given (" << addr_user << ") has: " << *p_addr_user << endl;
return( 0 );
}
Sorry, I was not so clear:
What the program must to do:
ask to type an integer, print the memory address from those integer, ask to type the memory address printed above, print the content of that memory address and confirm if that address has the number typed in step one.
All in one runtime. Thank you in advance.
I tried this out in Linux:
g++ q.cpp
q.cpp: In function ‘int main()’:
q.cpp:17:31: warning: cast to pointer from integer of different size [-Wint-to-pointer- cast]
./a.out
Var: num, address: 0x7fff562d2828, has: 123456
Var: *addr, address: 0x7fff562d2818, has: 0x7fff562d2828
Printing value of num using the pointer *addr: 123456
Type the memory address: 0x7fff562d2828
Segmentation fault (core dumped)
So I notice a couple of issues:
I Naturally want to try to put in the address of num, but it is displayed in hex
Seg fault
To input in hex I change the input line to:
cout << "Type the memory address: "; cin >> hex >> addr_user;
(otherwise it is interpreted as 0)
But it is still segfaulting.
Here's the problem:
int *p_addr_user = (int*)addr_user;
Oh, there was a warning about it above. Sometime about different sizes (also note that pointers are unsigned.)
ints and pointers can be different sizes (it depends on your platform) For me int is 32 bit and pointers are 64 bit.
Here's how I got it working:
#include <stdint.h>
#...
uintptr_t addr_user;
cout << "Type the memory address: "; cin >> hex >> addr_user;
uintptr_t *p_addr_user =(uintptr_t*) addr_user;