|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
Please understand that I am asking here and it is NOT a Qt question.
My task is to start a new process - the parameters are "application" and its parameters.
The basic process builds a "Database" and I am not so sure about "bin/sh" - I guess it "runs" a shell...
It works and there is no need to get into why at this point.
The "problem" is - the "process" is running and I need to interact with it.
I can use "write" but I have no idea when and where and how.
In the enclosed snippet the "info\n" is "send" to the file ( shell?) before it is finished...
I do understand that Qt process can "wait for finished " and I can also get a SIGNAL when the file is actually done building. What I do not get - if the process is actually /physically building / writing a file - what does "wait for finished " waiting for ?
Again - I am not asking how to code Qt , I am asking how to code so I can "write" the additional stuff in right time.
std::string Database = BT_DATABASE_TEST;
std::string Command = "bluetoothctl ";
std::string command = Command + std::string(" | tee ") + Database + std::string(" | tee /tmp/temp");
QP->start("/bin/sh", QStringList() << "-c" << command.c_str());
qDebug()<< "TEST QProcess CONTINUE DEBUG point @line " << QString::number(__LINE__);
QP->waitForFinished();
QP->write("info\n"); writes too soon
qDebug() << QP->readAllStandardError();
qDebug() << QP->readAllStandardOutput();
|
|
|
|
|
1. Why putting #define in char "string" won't process the "command" to "start a new process" , however,
compiler is not giving an error ?
In debug mode I have literal BT_DATABASE_TEST in "command",
2. I need to make the primary text (*.txt) file a variable - how ?
#define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
const char *command = "bluetoothctl show | tee ../../BT_DATABASE/BluetoothDatabase.txt | tee /tmp/temp";
QP->start("/bin/sh", QStringList() << "-c" << command);
|
|
|
|
|
1. You can concatenate strings. Like this:
#define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
const char *command = "bluetoothctl show | tee " BT_DATABASE_TEXT " | tee /tmp/temp";
2. Maybe something like this:
std::string var = "blah_blah.txt";
std::string command = std::string("bluetoothctl show | tee ") + var + std::string("" | tee /tmp/temp");
QP->start("/bin/sh", QStringList() << "-c" << command.c_str());
Mircea
|
|
|
|
|
Basically I can build a string then "convert it" to char, Neat trick. Thanks
|
|
|
|
|
Member 14968771 wrote: 1. Why putting #define in char "string"... The preprocessor does not see #define directives inside string literals.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I can`t think of a way to store in an array objects of different type but with same base class so I`m going to use a STL container instead:
class somebaseclass
{
}
class derivedclass: private somebaseclass
{
}
class anotherderivedclass: private somebaseclass
{
}
vector<somebaseclass *> * AllObjects;
derivedclass * Derived1 = new derivedclass[1];
anotherderivedclass * Derived2 = new anotherderivedclass[1];
AllObjects->push_back((somebaseclass)Derived1);
AllObjects->push_back((somebaseclass)Derived2);
Is this how it should be done?
modified 2 days ago.
|
|
|
|
|
That works but the more modern (and safe) way to do it is to use unique_ptr instead of raw pointers. Something like this:
std::unique_ptr<Base> p1 = make_unique<Derived1>(args1);
std::unique_ptr<Base> p2 = make_unique<Derived2>(args2);
std::vector<std::uniqe_ptr<Base>> container;
container.push_back (p1);
container.push_back (p2);
Mircea
|
|
|
|
|
Yes. If objects belong to different classes, the only way to store them in a container is to use pointers, because the container allocates the same amount of memory for each entry. If you also want the container to delete an entry when you erase it, declare it as, for example, vector<unique_ptr<T> >.
|
|
|
|
|
Quote: because the container allocates the same amount of memory for each entry
that is an interesting fact
modified 2 days ago.
|
|
|
|
|
Yes, except for:
1. Why are you using an array size reference in your instantiations? All you should need is:
derivedclass * Derived1 = new derivedclass();
2. Your container is defined to use somebaseclass * types, so your calls to push_back should be:
AllObject->push_back((somebaseclass*)Derived1);
or better still, using proper C++ casts:
AllObject->push_back(reinterpret_cast<somebaseclass*>(Derived1));
|
|
|
|
|
|
You are welcome. I also think @Mircea-Neacsu's advice about unique_ptr is well worth taking.
|
|
|
|
|
pointers from a library, that`s a topic that`s a bit too advanced or complicated for my present day understanding.
|
|
|
|
|
If you can handle raw pointers, then C++ smart pointers should be easy to understand. Google for C++ unique_pointer tutorial and read through a few of the returned hits. It's fairly straight forward, and in general new C++ development should use the smart pointers instead of using raw (e.g. new/delete).
Keep Calm and Carry On
|
|
|
|
|
The problem is I hate complicated syntax. Containers are already complicated syntax for me, combine that with another object (pointer) from a library and it becomes unintelligible mess. I will use a complicated feature when I really need to use it and there is no other way around it. Usually I need to use a feature a couple months before I can move on to something more complicated.
|
|
|
|
|
It's a lot simpler than classes and inheritance. 
|
|
|
|
|
Richard you really think so?
|
|
|
|
|
Did you notice the icon?
|
|
|
|
|
|
I guess converting the object(pointer) back to it`s original form when time comes to use it somewhere works the same
derivedclass * DerClpointer1 = (derivedclass *)AllObjects->at(0);
Is there a way to check is the conversion is valid? like if an object is of a certain type. For instance how do I convert all objects to their derived state type in a for loop?
for(int i =0; i< AllObjects->size();i++ )
{
}
modified 1hr 10mins ago.
|
|
|
|
|
I`m trying to animate things in a basic window. The code I have should get a rectangle (rc) move to the right however that does not happen, it`s all static.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static RECT rcBmp;
static HDC hdcCompat;
static HBITMAP hbmp;
static RECT rc;
static RECT rc2;
static RECT rc3;
static RECT rc4;
HBRUSH hbrWhite, hbrGray;
const COLORREF SomeColor = RGB(255,255,255);
const COLORREF SomeColor2 = RGB(0,0,1);
hbrWhite = CreateSolidBrush(SomeColor);
hbrGray = CreateSolidBrush(SomeColor2);
int y = 0;
HDC hdc = (HDC) wParam;
switch (uMsg)
{
case WM_CREATE:
return 0L;
case WM_ERASEBKGND:
GetClientRect(hwnd, &rc);
SetMapMode(hdc, MM_ANISOTROPIC);
SetWindowExtEx(hdc, 100, 100, NULL);
SetViewportExtEx(hdc, rc.right, rc.bottom, NULL);
FillRect(hdc, &rc, hbrWhite);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
SetRect(&rc,x, 20, 40, 40);
FillRect(hdc, &rc, hbrGray);
SetRect(&rc2,60, 60, 80, 80);
FillRect(hdc, &rc2, hbrGray);
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void GameUpdate()
{
x = x +1;
}
[Edit] it looks like WM_PAINT isn`t triggered every frame, only if I minimize and then maximize the window a change takes place
modified 3 days ago.
|
|
|
|
|
I think you need an "event"; like a timer tick; in order to create a "frame loop" (update and paint).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Windows is event-driven, it doesn't have regular animation frame updates.
You can use SetTimer() to get WM_TIMER messages as often as you want, then invalidate your window to get the WM_PAINT message and repaint.
GDI performance is not very good though, so to reduce flicker you'll probably want to draw to an offscreen compatible device context and then BitBlt() that to the screen. Or use Direct2D - but then you'll have a new problem to think about.
|
|
|
|